@@ -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()
+ if (once && cb) {
+ const _cb = cb
+ cb = (...args) => {
+ _cb(...args)
+ watchHandle()