Skip to content

Commit 34e750f

Browse files
committed
fix: remove elusive code for once
1 parent 589cd11 commit 34e750f

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

packages/reactivity/src/baseWatch.ts

+12-22
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
} from './effect'
2323
import { isReactive, isShallow } from './reactive'
2424
import { type Ref, isRef } from './ref'
25-
import { getCurrentScope } from './effectScope'
2625

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

246245
if (once) {
247-
if (!cb) {
248-
// onWatcherCleanup need use effect as a key
249-
getCurrentScope()?.effects.push((effect = {} as any))
250-
getter()
251-
return
252-
}
253-
if (immediate) {
254-
// onWatcherCleanup need use effect as a key
255-
getCurrentScope()?.effects.push((effect = {} as any))
256-
callWithAsyncErrorHandling(
257-
cb,
258-
onError,
259-
BaseWatchErrorCodes.WATCH_CALLBACK,
260-
[getter(), isMultiSource ? [] : undefined, onWatcherCleanup],
261-
)
262-
return
263-
}
264-
const _cb = cb
265-
cb = (...args) => {
266-
_cb(...args)
267-
effect?.stop()
246+
if (cb) {
247+
const _cb = cb
248+
cb = (...args) => {
249+
_cb(...args)
250+
effect?.stop()
251+
}
252+
} else {
253+
const _getter = getter
254+
getter = () => {
255+
_getter()
256+
effect?.stop()
257+
}
268258
}
269259
}
270260

0 commit comments

Comments
 (0)