File tree 2 files changed +24
-2
lines changed
2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 6
6
TrackOpTypes ,
7
7
TriggerOpTypes ,
8
8
DebuggerEvent ,
9
- markRaw
9
+ markRaw ,
10
+ shallowReactive
10
11
} from '../src/index'
11
12
import { ITERATE_KEY } from '../src/effect'
12
13
@@ -811,4 +812,24 @@ describe('reactivity/effect', () => {
811
812
expect ( dummy ) . toBe ( 0 )
812
813
expect ( record ) . toBeUndefined ( )
813
814
} )
815
+
816
+ it ( 'should trigger once effect when set the equal proxy' , ( ) => {
817
+ const obj = reactive ( { foo : 1 } )
818
+ const observed : any = reactive ( { obj } )
819
+ const fnSpy = jest . fn ( ( ) => observed . obj )
820
+
821
+ effect ( fnSpy )
822
+
823
+ observed . obj = obj
824
+ expect ( fnSpy ) . toHaveBeenCalledTimes ( 1 )
825
+
826
+ const obj2 = reactive ( { foo : 1 } )
827
+ const observed2 : any = shallowReactive ( { obj2 } )
828
+ const fnSpy2 = jest . fn ( ( ) => observed2 . obj2 )
829
+
830
+ effect ( fnSpy2 )
831
+
832
+ observed2 . obj2 = obj2
833
+ expect ( fnSpy2 ) . toHaveBeenCalledTimes ( 1 )
834
+ } )
814
835
} )
Original file line number Diff line number Diff line change @@ -146,9 +146,10 @@ function createSetter(shallow = false) {
146
146
value : unknown ,
147
147
receiver : object
148
148
) : boolean {
149
- const oldValue = ( target as any ) [ key ]
149
+ let oldValue = ( target as any ) [ key ]
150
150
if ( ! shallow ) {
151
151
value = toRaw ( value )
152
+ oldValue = toRaw ( oldValue )
152
153
if ( ! isArray ( target ) && isRef ( oldValue ) && ! isRef ( value ) ) {
153
154
oldValue . value = value
154
155
return true
You can’t perform that action at this time.
0 commit comments