forked from mobxjs/mobx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisobservable.ts
More file actions
53 lines (50 loc) · 1.61 KB
/
Copy pathisobservable.ts
File metadata and controls
53 lines (50 loc) · 1.61 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
44
45
46
47
48
49
50
51
52
53
import {
$mobx,
ObservableObjectAdministration,
fail,
isAtom,
isComputedValue,
isObservableArray,
isObservableMap,
isObservableObject,
isReaction
} from "../internal"
function _isObservable(value, property?: string): boolean {
if (value === null || value === undefined) return false
if (property !== undefined) {
if (
process.env.NODE_ENV !== "production" &&
(isObservableMap(value) || isObservableArray(value))
)
return fail(
"isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead."
)
if (isObservableObject(value)) {
return (<ObservableObjectAdministration>(value as any)[$mobx]).values.has(property)
}
return false
}
// For first check, see #701
return (
isObservableObject(value) ||
!!value[$mobx] ||
isAtom(value) ||
isReaction(value) ||
isComputedValue(value)
)
}
export function isObservable(value: any): boolean {
if (arguments.length !== 1)
fail(
process.env.NODE_ENV !== "production" &&
`isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property`
)
return _isObservable(value)
}
export function isObservableProp(value: any, propName: string): boolean {
if (typeof propName !== "string")
return fail(
process.env.NODE_ENV !== "production" && `expected a property name as second argument`
)
return _isObservable(value, propName)
}