File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -611,4 +611,23 @@ describe('api: watch', () => {
611611 oldValue : 2
612612 } )
613613 } )
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+ } )
614633} )
Original file line number Diff line number Diff line change @@ -71,8 +71,6 @@ export interface WatchOptions<Immediate = boolean> extends WatchOptionsBase {
7171
7272export type WatchStopHandle = ( ) => void
7373
74- const invoke = ( fn : Function ) => fn ( )
75-
7674// Simple effect.
7775export function watchEffect (
7876 effect : WatchEffect ,
@@ -262,7 +260,7 @@ function doWatch(
262260
263261 let scheduler : ( job : ( ) => any ) => void
264262 if ( flush === 'sync' ) {
265- scheduler = invoke
263+ scheduler = job
266264 } else if ( flush === 'pre' ) {
267265 // ensure it's queued before component updates (which have positive ids)
268266 job . id = - 1
You can’t perform that action at this time.
0 commit comments