1 | import {
|
2 | IArrayWillChange,
|
3 | IArrayWillSplice,
|
4 | IInterceptor,
|
5 | IMapWillChange,
|
6 | IObjectWillChange,
|
7 | IObservableArray,
|
8 | IObservableValue,
|
9 | IValueWillChange,
|
10 | Lambda,
|
11 | ObservableMap,
|
12 | getAdministration,
|
13 | ObservableSet,
|
14 | ISetWillChange,
|
15 | isFunction
|
16 | } from "../internal"
|
17 |
|
18 | export function intercept<T>(
|
19 | value: IObservableValue<T>,
|
20 | handler: IInterceptor<IValueWillChange<T>>
|
21 | ): Lambda
|
22 | export function intercept<T>(
|
23 | observableArray: IObservableArray<T>,
|
24 | handler: IInterceptor<IArrayWillChange<T> | IArrayWillSplice<T>>
|
25 | ): Lambda
|
26 | export function intercept<K, V>(
|
27 | observableMap: ObservableMap<K, V> | Map<K, V>,
|
28 | handler: IInterceptor<IMapWillChange<K, V>>
|
29 | ): Lambda
|
30 | export function intercept<V>(
|
31 | observableSet: ObservableSet<V> | Set<V>,
|
32 | handler: IInterceptor<ISetWillChange<V>>
|
33 | ): Lambda
|
34 | export function intercept<K, V>(
|
35 | observableMap: ObservableMap<K, V> | Map<K, V>,
|
36 | property: K,
|
37 | handler: IInterceptor<IValueWillChange<V>>
|
38 | ): Lambda
|
39 | export function intercept(object: object, handler: IInterceptor<IObjectWillChange>): Lambda
|
40 | export function intercept<T extends object, K extends keyof T>(
|
41 | object: T,
|
42 | property: K,
|
43 | handler: IInterceptor<IValueWillChange<T[K]>>
|
44 | ): Lambda
|
45 | export function intercept(thing, propOrHandler?, handler?): Lambda {
|
46 | if (isFunction(handler)) return interceptProperty(thing, propOrHandler, handler)
|
47 | else return interceptInterceptable(thing, propOrHandler)
|
48 | }
|
49 |
|
50 | function interceptInterceptable(thing, handler) {
|
51 | return getAdministration(thing).intercept_(handler)
|
52 | }
|
53 |
|
54 | function interceptProperty(thing, property, handler) {
|
55 | return getAdministration(thing, property).intercept_(handler)
|
56 | }
|
57 |
|
\ | No newline at end of file |