@@ -50,10 +50,13 @@ export interface WatchOptions<Immediate = boolean> extends DebuggerOptions {
5050 scheduler ?: WatchScheduler
5151 onWarn ?: ( msg : string , ...args : any [ ] ) => void
5252 /**
53+ * Augment callback as scheduler job for special handling in core scheduler
5354 * @internal
5455 */
5556 augmentJob ?: ( job : ( ...args : any [ ] ) => void ) => void
5657 /**
58+ * Call a user-provided callback with error handling
59+ * runtime-core will pass `callWithAsyncErrorHandling` with instance
5760 * @internal
5861 */
5962 call ?: (
@@ -137,9 +140,9 @@ export function watch(
137140 }
138141
139142 let effect : ReactiveEffect
140- let boundCleanup : typeof onWatcherCleanup
141143 let getter : ( ) => any
142144 let cleanup : ( ( ) => void ) | undefined
145+ let boundCleanup : typeof onWatcherCleanup // `onCleanup` passed to callbacks
143146 let forceTrigger = false
144147 let isMultiSource = false
145148
@@ -277,12 +280,9 @@ export function watch(
277280 }
278281
279282 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 )
286286
287287 cleanup = effect . onStop = ( ) => {
288288 const cleanups = cleanupMap . get ( effect )
@@ -296,6 +296,8 @@ export function watch(
296296 }
297297 }
298298
299+ boundCleanup = fn => onWatcherCleanup ( fn , false , effect )
300+
299301 if ( __DEV__ ) {
300302 effect . onTrack = options . onTrack
301303 effect . onTrigger = options . onTrigger
0 commit comments