-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
mobx.ts
164 lines (158 loc) · 4.33 KB
/
mobx.ts
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
* (c) Michel Weststrate 2015 - 2018
* MIT Licensed
*
* Welcome to the mobx sources! To get an global overview of how MobX internally works,
* this is a good place to start:
* https://medium.com/@mweststrate/becoming-fully-reactive-an-in-depth-explanation-of-mobservable-55995262a254#.xvbh6qd74
*
* Source folders:
* ===============
*
* - api/ Most of the public static methods exposed by the module can be found here.
* - core/ Implementation of the MobX algorithm; atoms, derivations, reactions, dependency trees, optimizations. Cool stuff can be found here.
* - types/ All the magic that is need to have observable objects, arrays and values is in this folder. Including the modifiers like `asFlat`.
* - utils/ Utility stuff.
*
*/
if (typeof Proxy === "undefined" || typeof Symbol === "undefined") {
throw new Error(
"[mobx] MobX 5+ requires Proxy and Symbol objects. If your environment doesn't support Proxy objects, please downgrade to MobX 4. For React Native Android, consider upgrading JSCore."
)
}
declare var window: any
try {
// define process.env if needed
// if this is not a production build in the first place
// (in which case the expression below would be substituted with 'production')
process.env.NODE_ENV
} catch (e) {
const g = typeof window !== "undefined" ? window : global
if (typeof process === "undefined") g.process = {}
g.process.env = {}
}
;(() => {
function testCodeMinification() {}
if (
testCodeMinification.name !== "testCodeMinification" &&
process.env.NODE_ENV !== "production" &&
process.env.IGNORE_MOBX_MINIFY_WARNING !== "true"
) {
console.warn(
// Template literal(backtick) is used for fix issue with rollup-plugin-commonjs https://github.com/rollup/rollup-plugin-commonjs/issues/344
`[mobx] you are running a minified build, but 'process.env.NODE_ENV' was not set to 'production' in your bundler. This results in an unnecessarily large and slow bundle`
)
}
})()
export {
IObservable,
IDepTreeNode,
Reaction,
IReactionPublic,
IReactionDisposer,
IDerivation,
untracked,
IDerivationState,
IAtom,
createAtom,
IAction,
spy,
IComputedValue,
IEqualsComparer,
comparer,
IEnhancer,
IInterceptable,
IInterceptor,
IListenable,
IObjectWillChange,
IObjectDidChange,
IObservableObject,
isObservableObject,
IValueDidChange,
IValueWillChange,
IObservableValue,
isObservableValue as isBoxedObservable,
IObservableArray,
IArrayWillChange,
IArrayWillSplice,
IArrayChange,
IArraySplice,
isObservableArray,
IKeyValueMap,
ObservableMap,
IMapEntries,
IMapEntry,
IMapWillChange,
IMapDidChange,
isObservableMap,
IObservableMapInitialValues,
transaction,
observable,
IObservableFactory,
IObservableFactories,
computed,
IComputed,
isObservable,
isObservableProp,
isComputed,
isComputedProp,
extendObservable,
observe,
intercept,
autorun,
IAutorunOptions,
reaction,
IReactionOptions,
when,
IWhenOptions,
action,
isAction,
runInAction,
IActionFactory,
keys,
values,
entries,
set,
remove,
has,
get,
decorate,
configure,
onBecomeObserved,
onBecomeUnobserved,
flow,
castFlowReturn,
toJS,
trace,
IObserverTree,
IDependencyTree,
getDependencyTree,
getObserverTree,
resetGlobalState as _resetGlobalState,
getGlobalState as _getGlobalState,
getDebugName,
getAtom,
getAdministration as _getAdministration,
allowStateChanges as _allowStateChanges,
allowStateChangesInsideComputed as _allowStateChangesInsideComputed,
Lambda,
isArrayLike,
$mobx,
isComputingDerivation as _isComputingDerivation,
onReactionError,
interceptReads as _interceptReads,
IComputedValueOptions
} from "./internal"
// Devtools support
import { spy, getDebugName, $mobx } from "./internal"
declare var __MOBX_DEVTOOLS_GLOBAL_HOOK__: { injectMobx: ((any) => void) }
if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
// See: https://github.com/andykog/mobx-devtools/
__MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobx({
spy,
extras: {
getDebugName
},
$mobx
})
}