mirror of https://github.com/vuejs/core.git
fix(watch): `once` option should be ignored by watchEffect (#11884)
This commit is contained in:
parent
2d6adf78a0
commit
49fa673493
|
@ -193,4 +193,20 @@ describe('watch', () => {
|
|||
scope.stop()
|
||||
expect(calls).toEqual(['sync 2', 'post 2'])
|
||||
})
|
||||
|
||||
test('once option should be ignored by simple watch', async () => {
|
||||
let dummy: any
|
||||
const source = ref(0)
|
||||
watch(
|
||||
() => {
|
||||
dummy = source.value
|
||||
},
|
||||
null,
|
||||
{ once: true },
|
||||
)
|
||||
expect(dummy).toBe(0)
|
||||
|
||||
source.value++
|
||||
expect(dummy).toBe(1)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -218,19 +218,11 @@ export function watch(
|
|||
}
|
||||
}
|
||||
|
||||
if (once) {
|
||||
if (cb) {
|
||||
const _cb = cb
|
||||
cb = (...args) => {
|
||||
_cb(...args)
|
||||
watchHandle()
|
||||
}
|
||||
} else {
|
||||
const _getter = getter
|
||||
getter = () => {
|
||||
_getter()
|
||||
watchHandle()
|
||||
}
|
||||
if (once && cb) {
|
||||
const _cb = cb
|
||||
cb = (...args) => {
|
||||
_cb(...args)
|
||||
watchHandle()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue