We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
oldValue
cb
1 parent 1a66474 commit c69c4bbCopy full SHA for c69c4bb
packages/reactivity/__tests__/watch.spec.ts
@@ -277,4 +277,16 @@ describe('watch', () => {
277
278
expect(dummy).toEqual([1, 2, 3])
279
})
280
+
281
+ test('watch with immediate reset and sync flush', () => {
282
+ const value = ref(false)
283
284
+ watch(value, () => {
285
+ value.value = false
286
+ })
287
288
+ value.value = true
289
290
+ expect(value.value).toBe(false)
291
292
packages/reactivity/src/watch.ts
@@ -264,11 +264,11 @@ export function watch(
264
: oldValue,
265
boundCleanup,
266
]
267
+ oldValue = newValue
268
call
269
? call(cb!, WatchErrorCodes.WATCH_CALLBACK, args)
270
: // @ts-expect-error
271
cb!(...args)
- oldValue = newValue
272
} finally {
273
activeWatcher = currentWatcher
274
}
0 commit comments