diff --git a/packages/redox/src/core/__tests__/reducer.test.ts b/packages/redox/src/core/__tests__/reducer.test.ts index 25afb2c..8d21d65 100644 --- a/packages/redox/src/core/__tests__/reducer.test.ts +++ b/packages/redox/src/core/__tests__/reducer.test.ts @@ -98,6 +98,24 @@ describe('defineModel/reducers', () => { }) describe('immer', () => { + it('should not update with do nothing', () => { + const count = defineModel({ + name: 'count', + state: { value: 0 }, + reducers: { + add(_state) {}, + }, + }) + + const store = redoxStore.getModel(count) + + const $state = store.$state + + store.add() + + expect(store.$state).toBe($state) + }) + it('should work with a basic literal', () => { const count = defineModel({ name: 'count', diff --git a/packages/redox/src/core/model.ts b/packages/redox/src/core/model.ts index 5f2d1fd..6972a52 100644 --- a/packages/redox/src/core/model.ts +++ b/packages/redox/src/core/model.ts @@ -9,7 +9,6 @@ import { effectScope, EffectScope, onViewInvalidate, - isReactive, } from '../reactivity' import { AnyModel } from './defineModel' import { Views, Actions, Action, State, StateObject } from './modelOptions' @@ -216,11 +215,7 @@ export class ModelInternal { if (state === undefined) return reducer(state, action.payload) as IModel['state'] return produce( - isReactive(this.state) - ? this.state - : isObject(this.state) - ? reactive(this.state) - : this.state, + isObject(state) ? reactive(state) : state, (draft: any) => reducer!(draft, action.payload) as IModel['state'] ) } diff --git a/packages/redox/src/reactivity/__tests__/producer.test.ts b/packages/redox/src/reactivity/__tests__/producer.test.ts index 3f4a5a2..b1c67f9 100644 --- a/packages/redox/src/reactivity/__tests__/producer.test.ts +++ b/packages/redox/src/reactivity/__tests__/producer.test.ts @@ -1277,6 +1277,10 @@ describe(`reactivity/producer`, () => { expect(child.b).toBe(2) // changed expect(child.c).toBe(2) // added expect(child.d).toBeUndefined() // deleted + child.f = 2 + produce(reactive(child), (s) => { + console.log(s.f) + }) }) }) }) diff --git a/packages/redox/src/reactivity/index.ts b/packages/redox/src/reactivity/index.ts index 0d1ebb2..5d82c96 100644 --- a/packages/redox/src/reactivity/index.ts +++ b/packages/redox/src/reactivity/index.ts @@ -1,10 +1,4 @@ -export { - toReactive, - toReadonly, - reactive, - readonly, - isReactive, -} from './reactive' +export { toReactive, toReadonly, reactive, readonly } from './reactive' export { View, view, ViewGetter, onViewInvalidate } from './view' export { ReactiveEffect } from './effect' export { EffectScope, effectScope } from './effectScope'