8000 feat(watchOnce): return function for manual watcher stopping (#3475) · vueuse/vueuse@bb0a78e · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit bb0a78e

Browse files
feat(watchOnce): return function for manual watcher stopping (#3475)
1 parent f9136e8 commit bb0a78e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/shared/watchOnce/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
import type { WatchCallback, WatchOptions, WatchSource } from 'vue-demi'
1+
import type { WatchCallback, WatchOptions, WatchSource, WatchStopHandle } from 'vue-demi'
22
import { nextTick, watch } from 'vue-demi'
33
import type { MapOldSources, MapSources } from '../utils'
44

55
// overloads
6-
export function watchOnce<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(source: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchOptions<Immediate>): void
6+
export function watchOnce<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(source: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchOptions<Immediate>): WatchStopHandle
77

8-
export function watchOnce<T, Immediate extends Readonly<boolean> = false>(sources: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchOptions<Immediate>): void
8+
export function watchOnce<T, Immediate extends Readonly<boolean> = false>(sources: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchOptions<Immediate>): WatchStopHandle
99

1010
// implementation
1111
export function watchOnce<Immediate extends Readonly<boolean> = false>(
1212
source: any,
1313
cb: any,
1414
options?: WatchOptions<Immediate>,
15-
): void {
15+
): WatchStopHandle {
1616
const stop = watch(source, (...args) => {
1717
nextTick(() => stop())
1818

1919
return cb(...args)
2020
}, options)
21+
22+
return stop
2123
}

0 commit comments

Comments
 (0)
0