fix(watch): callback not called when using flush:sync
(#1633)
This commit is contained in:
parent
4655d69983
commit
8facaefcc3
@ -611,4 +611,23 @@ describe('api: watch', () => {
|
|||||||
oldValue: 2
|
oldValue: 2
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should work sync', () => {
|
||||||
|
const v = ref(1)
|
||||||
|
let calls = 0
|
||||||
|
|
||||||
|
watch(
|
||||||
|
v,
|
||||||
|
() => {
|
||||||
|
++calls
|
||||||
|
},
|
||||||
|
{
|
||||||
|
flush: 'sync'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(calls).toBe(0)
|
||||||
|
v.value++
|
||||||
|
expect(calls).toBe(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -71,8 +71,6 @@ export interface WatchOptions<Immediate = boolean> extends WatchOptionsBase {
|
|||||||
|
|
||||||
export type WatchStopHandle = () => void
|
export type WatchStopHandle = () => void
|
||||||
|
|
||||||
const invoke = (fn: Function) => fn()
|
|
||||||
|
|
||||||
// Simple effect.
|
// Simple effect.
|
||||||
export function watchEffect(
|
export function watchEffect(
|
||||||
effect: WatchEffect,
|
effect: WatchEffect,
|
||||||
@ -262,7 +260,7 @@ function doWatch(
|
|||||||
|
|
||||||
let scheduler: (job: () => any) => void
|
let scheduler: (job: () => any) => void
|
||||||
if (flush === 'sync') {
|
if (flush === 'sync') {
|
||||||
scheduler = invoke
|
scheduler = job
|
||||||
} else if (flush === 'pre') {
|
} else if (flush === 'pre') {
|
||||||
// ensure it's queued before component updates (which have positive ids)
|
// ensure it's queued before component updates (which have positive ids)
|
||||||
job.id = -1
|
job.id = -1
|
||||||
|
Loading…
Reference in New Issue
Block a user