Repository navigation
Expand file tree
/
Copy pathmobx.ts
More file actions
189 lines (174 loc) · 6.4 KB
/
Copy pathmobx.ts
File metadata and controls
189 lines (174 loc) · 6.4 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/**
* (c) Michel Weststrate 2015 - 2016
* 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.
*
*/
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) {
var 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"
) {
console.warn(
"[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 } from "./core/observable"
export { Reaction, IReactionPublic, IReactionDisposer } from "./core/reaction"
export { IDerivation, untracked, IDerivationState } from "./core/derivation"
export { IAtom, createAtom } from "./core/atom"
export { IAction } from "./core/action"
export { spy } from "./core/spy"
export { IComputedValue } from "./core/computedvalue"
export { IEqualsComparer, comparer } from "./utils/comparer"
export { IEnhancer } from "./types/modifiers"
export { IInterceptable, IInterceptor } from "./types/intercept-utils"
export { IListenable } from "./types/listen-utils"
export {
IObjectWillChange,
IObjectDidChange,
IObservableObject,
isObservableObject
} from "./types/observableobject"
export {
IValueDidChange,
IValueWillChange,
IObservableValue,
isObservableValue as isBoxedObservable
} from "./types/observablevalue"
export {
IObservableArray,
IArrayWillChange,
IArrayWillSplice,
IArrayChange,
IArraySplice,
isObservableArray
} from "./types/observablearray"
export {
IKeyValueMap,
ObservableMap,
IMapEntries,
IMapEntry,
IMapWillChange,
IMapDidChange,
isObservableMap,
IObservableMapInitialValues
} from "./types/observablemap"
export { transaction } from "./api/transaction"
export { observable, IObservableFactory, IObservableFactories } from "./api/observable"
export { computed, IComputed } from "./api/computed"
export { isObservable, isObservableProp } from "./api/isobservable"
export { isComputed, isComputedProp } from "./api/iscomputed"
export { extendObservable, extendShallowObservable } from "./api/extendobservable"
export { observe } from "./api/observe"
export { intercept } from "./api/intercept"
export { autorun, reaction, IReactionOptions } from "./api/autorun"
export { when, IWhenOptions } from "./api/when"
export { action, isAction, runInAction, IActionFactory } from "./api/action"
export { keys, values, set, remove, has, get } from "./api/object-api"
export { decorate } from "./api/decorate"
export { configure } from "./api/configure"
export { onBecomeObserved, onBecomeUnobserved } from "./api/become-observed"
export { flow } from "./api/flow"
export { toJS } from "./api/tojs"
export { trace } from "./api/trace"
export { IObserverTree, IDependencyTree, getDependencyTree, getObserverTree } from "./api/extras"
export {
resetGlobalState as _resetGlobalState,
getGlobalState as _getGlobalState
} from "./core/globalstate"
export { getDebugName, getAtom, getAdministration as _getAdministration } from "./types/type-utils"
export { allowStateChanges as _allowStateChanges } from "./core/action"
export { Lambda, isArrayLike } from "./utils/utils"
export { isComputingDerivation as _isComputingDerivation } from "./core/derivation"
export { onReactionError } from "./core/reaction"
export { interceptReads as _interceptReads } from "./api/intercept-read"
export { IComputedValueOptions } from "./core/computedvalue"
// This line should come after all the imports as well, for the same reason
// as noted above. I will file a bug with rollupjs - @rossipedia
import "./core/globalstate"
// Devtools support
import { spy } from "./core/spy"
import { getDebugName } from "./types/type-utils"
import { fail } from "./utils/utils"
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
}
})
}
// TODO: remove in some future build
if (
process.env.NODE_ENV !== "production" &&
typeof module !== "undefined" &&
typeof module.exports !== "undefined"
) {
let warnedAboutDefaultExport = false
Object.defineProperty(module.exports, "default", {
enumerable: false,
get() {
if (!warnedAboutDefaultExport) {
warnedAboutDefaultExport = true
console.warn(
`The MobX package does not have a default export. Use 'import { thing } from "mobx"' (recommended) or 'import * as mobx from "mobx"' instead."`
)
}
return undefined
}
})
;[
"extras",
"Atom",
"BaseAtom",
"asFlat",
"asMap",
"asReference",
"asStructure",
"autorunAsync",
"createTranformer",
"expr",
"isModifierDescriptor",
"isStrictModeEnabled",
"map",
"useStrict",
"whyRun"
].forEach(prop => {
Object.defineProperty(module.exports, prop, {
enumerable: false,
get() {
fail(
`'${prop}' is no longer part of the public MobX api. Please consult the changelog to find out where this functionality went`
)
},
set() {}
})
})
}