File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -295,6 +295,7 @@ function createWatcher(
295
295
}
296
296
297
297
let deep = options . deep
298
+ let isMultiSource = false
298
299
299
300
let getter : ( ) => any
300
301
if ( isRef ( source ) ) {
@@ -303,6 +304,7 @@ function createWatcher(
303
304
getter = ( ) => source
304
305
deep = true
305
306
} else if ( isArray ( source ) ) {
307
+ isMultiSource = true
306
308
getter = ( ) =>
307
309
source . map ( ( s ) => {
308
310
if ( isRef ( s ) ) {
@@ -339,6 +341,8 @@ function createWatcher(
339
341
}
340
342
341
343
const applyCb = ( n : any , o : any ) => {
344
+ if ( isMultiSource && n . every ( ( v : any , i : number ) => Object . is ( v , o [ i ] ) ) )
345
+ return
342
346
// cleanup before running cb again
343
347
runCleanup ( )
344
348
return cb ( n , o , registerCleanup )
Original file line number Diff line number Diff line change 5
5
watch,
6
6
watchEffect,
7
7
set,
8
+ computed,
8
9
nextTick,
9
10
} = require ( '../../src' )
10
11
const { mockWarn } = require ( '../helpers' )
@@ -821,4 +822,28 @@ describe('api/watch', () => {
821
822
822
823
expect ( cb ) . toHaveBeenCalled ( )
823
824
} )
825
+
826
+ it ( 'watching sources: ref<[]>' , async ( ) => {
827
+ const foo = ref ( [ 1 ] )
828
+ const cb = jest . fn ( )
829
+ watch ( foo , cb )
830
+ foo . value = foo . value . slice ( )
831
+ await nextTick ( )
832
+ expect ( cb ) . toBeCalledTimes ( 1 )
833
+ } )
834
+
835
+ it ( 'watching multiple sources: computed' , async ( ) => {
836
+ const number = ref ( 1 )
837
+ const div2 = computed ( ( ) => {
838
+ return number . value > 2 ? '>2' : '<=2'
839
+ } )
840
+ const div3 = computed ( ( ) => {
841
+ return number . value > 3 ? '>3' : '<=3'
842
+ } )
843
+ const cb = jest . fn ( )
844
+ watch ( [ div2 , div3 ] , cb )
845
+ number . value = 2
846
+ await nextTick ( )
847
+ expect ( cb ) . toHaveBeenCalledTimes ( 0 )
848
+ } )
824
849
} )
You can’t perform that action at this time.
0 commit comments