Skip to content

feat(reactivity): base watch, getCurrentWatcher, and onWatcherCleanup #9927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: fix dts
  • Loading branch information
yyx990803 committed Aug 19, 2024
commit 4b92fca0a51c9841dd944d21197c5f3dc3488db5
20 changes: 6 additions & 14 deletions packages/reactivity/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,12 @@ export function onWatcherCleanup(
export function watch(
source: WatchSource | WatchSource[] | WatchEffect | object,
cb?: WatchCallback | null,
{
immediate,
deep,
once,
scheduler,
onWarn = __DEV__ ? warn : NOOP,
onTrack,
onTrigger,
augmentJob,
call,
}: WatchOptions = EMPTY_OBJ,
options: WatchOptions = EMPTY_OBJ,
): WatchHandle {
const { immediate, deep, once, scheduler, augmentJob, call } = options

const warnInvalidSource = (s: unknown) => {
onWarn(
;(options.onWarn || warn)(
`Invalid watch source: `,
s,
`A watch source can only be a getter/effect function, a ref, ` +
Expand Down Expand Up @@ -303,8 +295,8 @@ export function watch(
}

if (__DEV__) {
effect.onTrack = onTrack
effect.onTrigger = onTrigger
effect.onTrack = options.onTrack
effect.onTrigger = options.onTrigger
}

// initial run
Expand Down