Skip to content

Commit

Permalink
chore: minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Aug 20, 2024
1 parent 84033f0 commit a8ea136
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 9 additions & 7 deletions packages/reactivity/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ export interface WatchOptions<Immediate = boolean> extends DebuggerOptions {
scheduler?: WatchScheduler
onWarn?: (msg: string, ...args: any[]) => void
/**
* Augment callback as scheduler job for special handling in core scheduler
* @internal
*/
augmentJob?: (job: (...args: any[]) => void) => void
/**
* Call a user-provided callback with error handling
* runtime-core will pass `callWithAsyncErrorHandling` with instance
* @internal
*/
call?: (
Expand Down Expand Up @@ -137,9 +140,9 @@ export function watch(
}

let effect: ReactiveEffect
let boundCleanup: typeof onWatcherCleanup
let getter: () => any
let cleanup: (() => void) | undefined
let boundCleanup: typeof onWatcherCleanup // `onCleanup` passed to callbacks
let forceTrigger = false
let isMultiSource = false

Expand Down Expand Up @@ -277,12 +280,9 @@ export function watch(
}

effect = new ReactiveEffect(getter)
boundCleanup = fn => onWatcherCleanup(fn, false, effect)
if (scheduler) {
effect.scheduler = () => scheduler(job, false)
} else {
effect.scheduler = job as EffectScheduler
}
effect.scheduler = scheduler
? () => scheduler(job, false)
: (job as EffectScheduler)

cleanup = effect.onStop = () => {
const cleanups = cleanupMap.get(effect)
Expand All @@ -296,6 +296,8 @@ export function watch(
}
}

boundCleanup = fn => onWatcherCleanup(fn, false, effect)

if (__DEV__) {
effect.onTrack = options.onTrack
effect.onTrigger = options.onTrigger
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ function doWatch(

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

if (__DEV__) baseWatchOptions.onWarn = warn
if (__DEV__) {
baseWatchOptions.onWarn = warn
}

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

0 comments on commit a8ea136

Please sign in to comment.