File tree 2 files changed +20
-3
lines changed
2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -611,4 +611,23 @@ describe('api: watch', () => {
611
611
oldValue : 2
612
612
} )
613
613
} )
614
+
615
+ it ( 'should work sync' , ( ) => {
616
+ const v = ref ( 1 )
617
+ let calls = 0
618
+
619
+ watch (
620
+ v ,
621
+ ( ) => {
622
+ ++ calls
623
+ } ,
624
+ {
625
+ flush : 'sync'
626
+ }
627
+ )
628
+
629
+ expect ( calls ) . toBe ( 0 )
630
+ v . value ++
631
+ expect ( calls ) . toBe ( 1 )
632
+ } )
614
633
} )
Original file line number Diff line number Diff line change @@ -71,8 +71,6 @@ export interface WatchOptions<Immediate = boolean> extends WatchOptionsBase {
71
71
72
72
export type WatchStopHandle = ( ) => void
73
73
74
- const invoke = ( fn : Function ) => fn ( )
75
-
76
74
// Simple effect.
77
75
export function watchEffect (
78
76
effect : WatchEffect ,
@@ -262,7 +260,7 @@ function doWatch(
262
260
263
261
let scheduler : ( job : ( ) => any ) => void
264
262
if ( flush === 'sync' ) {
265
- scheduler = invoke
263
+ scheduler = job
266
264
} else if ( flush === 'pre' ) {
267
265
// ensure it's queued before component updates (which have positive ids)
268
266
job . id = - 1
You can’t perform that action at this time.
0 commit comments