UNPKG

1.71 kBPlain TextView Raw
1import {
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
18export function intercept<T>(
19 value: IObservableValue<T>,
20 handler: IInterceptor<IValueWillChange<T>>
21): Lambda
22export function intercept<T>(
23 observableArray: IObservableArray<T>,
24 handler: IInterceptor<IArrayWillChange<T> | IArrayWillSplice<T>>
25): Lambda
26export function intercept<K, V>(
27 observableMap: ObservableMap<K, V> | Map<K, V>,
28 handler: IInterceptor<IMapWillChange<K, V>>
29): Lambda
30export function intercept<V>(
31 observableSet: ObservableSet<V> | Set<V>,
32 handler: IInterceptor<ISetWillChange<V>>
33): Lambda
34export function intercept<K, V>(
35 observableMap: ObservableMap<K, V> | Map<K, V>,
36 property: K,
37 handler: IInterceptor<IValueWillChange<V>>
38): Lambda
39export function intercept(object: object, handler: IInterceptor<IObjectWillChange>): Lambda
40export function intercept<T extends object, K extends keyof T>(
41 object: T,
42 property: K,
43 handler: IInterceptor<IValueWillChange<T[K]>>
44): Lambda
45export function intercept(thing, propOrHandler?, handler?): Lambda {
46 if (isFunction(handler)) return interceptProperty(thing, propOrHandler, handler)
47 else return interceptInterceptable(thing, propOrHandler)
48}
49
50function interceptInterceptable(thing, handler) {
51 return getAdministration(thing).intercept_(handler)
52}
53
54function interceptProperty(thing, property, handler) {
55 return getAdministration(thing, property).intercept_(handler)
56}
57
\No newline at end of file