Skip to content

Commit

Permalink
fix: remove elusive code for once
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleSound committed Mar 13, 2024
1 parent 589cd11 commit a5769e1
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions packages/reactivity/src/baseWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
} from './effect'
import { isReactive, isShallow } from './reactive'
import { type Ref, isRef } from './ref'
import { getCurrentScope } from './effectScope'

// These errors were transferred from `packages/runtime-core/src/errorHandling.ts`
// along with baseWatch to maintain code compatibility. Hence,
Expand Down Expand Up @@ -244,27 +243,18 @@ export function baseWatch(
}

if (once) {
if (!cb) {
// onWatcherCleanup need use effect as a key
getCurrentScope()?.effects.push((effect = {} as any))
getter()
return
}
if (immediate) {
// onWatcherCleanup need use effect as a key
getCurrentScope()?.effects.push((effect = {} as any))
callWithAsyncErrorHandling(
cb,
onError,
BaseWatchErrorCodes.WATCH_CALLBACK,
[getter(), isMultiSource ? [] : undefined, onWatcherCleanup],
)
return
}
const _cb = cb
cb = (...args) => {
_cb(...args)
effect?.stop()
if (cb) {
const _cb = cb
cb = (...args) => {
_cb(...args)
effect?.stop()
}
} else {
const _getter = getter
getter = () => {
_getter()
effect?.stop()
}
}
}

Expand Down

0 comments on commit a5769e1

Please sign in to comment.