@@ -50,10 +50,13 @@ export interface WatchOptions<Immediate = boolean> extends DebuggerOptions {
50
50
scheduler ?: WatchScheduler
51
51
onWarn ?: ( msg : string , ...args : any [ ] ) => void
52
52
/**
53
+ * Augment callback as scheduler job for special handling in core scheduler
53
54
* @internal
54
55
*/
55
56
augmentJob ?: ( job : ( ...args : any [ ] ) => void ) => void
56
57
/**
58
+ * Call a user-provided callback with error handling
59
+ * runtime-core will pass `callWithAsyncErrorHandling` with instance
57
60
* @internal
58
61
*/
59
62
call ?: (
@@ -137,9 +140,9 @@ export function watch(
137
140
}
138
141
139
142
let effect : ReactiveEffect
140
- let boundCleanup : typeof onWatcherCleanup
141
143
let getter : ( ) => any
142
144
let cleanup : ( ( ) => void ) | undefined
145
+ let boundCleanup : typeof onWatcherCleanup // `onCleanup` passed to callbacks
143
146
let forceTrigger = false
144
147
let isMultiSource = false
145
148
@@ -277,12 +280,9 @@ export function watch(
277
280
}
278
281
279
282
effect = new ReactiveEffect ( getter )
280
- boundCleanup = fn => onWatcherCleanup ( fn , false , effect )
281
- if ( scheduler ) {
282
- effect . scheduler = ( ) => scheduler ( job , false )
283
- } else {
284
- effect . scheduler = job as EffectScheduler
285
- }
283
+ effect . scheduler = scheduler
284
+ ? ( ) => scheduler ( job , false )
285
+ : ( job as EffectScheduler )
286
286
287
287
cleanup = effect . onStop = ( ) => {
288
288
const cleanups = cleanupMap . get ( effect )
@@ -296,6 +296,8 @@ export function watch(
296
296
}
297
297
}
298
298
299
+ boundCleanup = fn => onWatcherCleanup ( fn , false , effect )
300
+
299
301
if ( __DEV__ ) {
300
302
effect . onTrack = options . onTrack
301
303
effect . onTrigger = options . onTrigger
0 commit comments