Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhe141 committed Sep 23, 2024
1 parent ff9c70a commit bad83a4
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions packages/reactivity/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,6 @@ export function watch(
? new Array((source as []).length).fill(INITIAL_WATCHER_VALUE)
: INITIAL_WATCHER_VALUE

const validateDeep = () => {
if (isFunction(source) && !isObject(oldValue)) {
return false
}
return deep
}

const job = (immediateFirstRun?: boolean) => {
if (
!(effect.flags & EffectFlags.ACTIVE) ||
Expand All @@ -248,11 +241,13 @@ export function watch(
// watch(source, cb)
const newValue = effect.run()
if (
validateDeep() ||
forceTrigger ||
(isMultiSource
? (newValue as any[]).some((v, i) => hasChanged(v, oldValue[i]))
: hasChanged(newValue, oldValue))
? (newValue as any[]).some(
(v, i) =>
(deep && isObject(v)) || hasChanged(v, (oldValue as any[])[i]),
)
: (deep && isObject(newValue)) || hasChanged(newValue, oldValue))
) {
// cleanup before running cb again
if (cleanup) {
Expand Down

0 comments on commit bad83a4

Please sign in to comment.