Skip to content

Commit a8ea136

Browse files
committed
chore: minor tweaks
1 parent 84033f0 commit a8ea136

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

packages/reactivity/src/watch.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

packages/runtime-core/src/apiWatch.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ function doWatch(
172172

173173
const baseWatchOptions: BaseWatchOptions = extend({}, options)
174174

175-
if (__DEV__) baseWatchOptions.onWarn = warn
175+
if (__DEV__) {
176+
baseWatchOptions.onWarn = warn
177+
}
176178

177179
let ssrCleanup: (() => void)[] | undefined
178180
if (__SSR__ && isInSSRComponentSetup) {

0 commit comments

Comments
 (0)