MCPcopy
hub / github.com/mobxjs/mobx / interceptReads

Function interceptReads

packages/mobx/src/api/intercept-read.ts:37–58  ·  view source on GitHub ↗
(thing, propOrHandler?, handler?)

Source from the content-addressed store, hash-verified

35 handler: ReadInterceptor<any>
36): Lambda
37export function interceptReads(thing, propOrHandler?, handler?): Lambda {
38 let target
39 if (isObservableMap(thing) || isObservableArray(thing) || isObservableValue(thing)) {
40 target = getAdministration(thing)
41 } else if (isObservableObject(thing)) {
42 if (__DEV__ && !isStringish(propOrHandler)) {
43 return die(
44 `InterceptReads can only be used with a specific property, not with an object in general`
45 )
46 }
47 target = getAdministration(thing, propOrHandler)
48 } else if (__DEV__) {
49 return die(`Expected observable map, object or array as first array`)
50 }
51 if (__DEV__ && target.dehancer !== undefined) {
52 return die(`An intercept reader was already established`)
53 }
54 target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler
55 return () => {
56 target.dehancer = undefined
57 }
58}

Callers

nothing calls this directly

Calls 6

isObservableMapFunction · 0.85
isStringishFunction · 0.85
dieFunction · 0.85
isObservableArrayFunction · 0.50
getAdministrationFunction · 0.50
isObservableObjectFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…