-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
index.ts
45 lines (40 loc) · 1.31 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { WatchCallback, WatchOptions, WatchSource, WatchStopHandle } from 'vue-demi'
import { watch } from 'vue-demi'
import type { MapOldSources, MapSources, MultiWatchSources } from '../utils/types'
// overloads
export function watchDeep<
T extends Readonly<MultiWatchSources>,
Immediate extends Readonly<boolean> = false,
>(
source: T,
cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
options?: Omit<WatchOptions<Immediate>, 'deep'>
): WatchStopHandle
export function watchDeep<T, Immediate extends Readonly<boolean> = false>(
source: WatchSource<T>,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: Omit<WatchOptions<Immediate>, 'deep'>
): WatchStopHandle
export function watchDeep<
T extends object,
Immediate extends Readonly<boolean> = false,
>(
source: T,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: Omit<WatchOptions<Immediate>, 'deep'>
): WatchStopHandle
/**
* Shorthand for watching value with {deep: true}
*
* @see https://vueuse.org/watchDeep
*/
export function watchDeep<T = any, Immediate extends Readonly<boolean> = false>(source: T | WatchSource<T>, cb: any, options?: Omit<WatchOptions<Immediate>, 'deep'>) {
return watch(
source as any,
cb,
{
...options,
deep: true,
},
)
}