File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -332,6 +332,11 @@ function createWatcher(
332
332
)
333
333
}
334
334
335
+ if ( deep ) {
336
+ const baseGetter = getter
337
+ getter = ( ) => traverse ( baseGetter ( ) )
338
+ }
339
+
335
340
const applyCb = ( n : any , o : any ) => {
336
341
// cleanup before running cb again
337
342
runCleanup ( )
Original file line number Diff line number Diff line change @@ -531,4 +531,23 @@ describe('api: watch', () => {
531
531
532
532
expect ( data2 . value ) . toMatchObject ( [ 1 ] )
533
533
} )
534
+
535
+ it ( 'watching deep ref' , async ( ) => {
536
+ const count = ref ( 0 )
537
+ const double = computed ( ( ) => count . value * 2 )
538
+ const state = reactive ( [ count , double ] )
539
+
540
+ let dummy
541
+ watch (
542
+ ( ) => state ,
543
+ ( state ) => {
544
+ dummy = [ state [ 0 ] . value , state [ 1 ] . value ]
545
+ } ,
546
+ { deep : true }
547
+ )
548
+
549
+ count . value ++
550
+ await nextTick ( )
551
+ expect ( dummy ) . toEqual ( [ 1 , 2 ] )
552
+ } )
534
553
} )
You can’t perform that action at this time.
0 commit comments