forked from mobxjs/mobx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintercept.ts
More file actions
43 lines (40 loc) · 1.67 KB
/
Copy pathintercept.ts
File metadata and controls
43 lines (40 loc) · 1.67 KB
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
import { IInterceptor } from "../types/intercept-utils"
import { IObservableArray, IArrayWillChange, IArrayWillSplice } from "../types/observablearray"
import { ObservableMap, IMapWillChange } from "../types/observablemap"
import { IObjectWillChange } from "../types/observableobject"
import { IValueWillChange, IObservableValue } from "../types/observablevalue"
import { Lambda } from "../utils/utils"
import { getAdministration } from "../types/type-utils"
export function intercept<T>(
value: IObservableValue<T>,
handler: IInterceptor<IValueWillChange<T>>
): Lambda
export function intercept<T>(
observableArray: IObservableArray<T>,
handler: IInterceptor<IArrayWillChange<T> | IArrayWillSplice<T>>
): Lambda
export function intercept<K, V>(
observableMap: ObservableMap<K, V>,
handler: IInterceptor<IMapWillChange<K, V>>
): Lambda
export function intercept<K, V>(
observableMap: ObservableMap<K, V>,
property: K,
handler: IInterceptor<IValueWillChange<V>>
): Lambda
export function intercept(object: Object, handler: IInterceptor<IObjectWillChange>): Lambda
export function intercept<T extends Object, K extends keyof T>(
object: T,
property: K,
handler: IInterceptor<IValueWillChange<any>>
): Lambda
export function intercept(thing, propOrHandler?, handler?): Lambda {
if (typeof handler === "function") return interceptProperty(thing, propOrHandler, handler)
else return interceptInterceptable(thing, propOrHandler)
}
function interceptInterceptable(thing, handler) {
return getAdministration(thing).intercept(handler)
}
function interceptProperty(thing, property, handler) {
return getAdministration(thing, property).intercept(handler)
}