mobx 4.9.4 → 4.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/api/configure.d.ts +1 -0
- package/lib/api/object-api.d.ts +1 -0
- package/lib/api/observable.d.ts +1 -0
- package/lib/core/globalstate.d.ts +5 -0
- package/lib/mobx.es6.js +4322 -0
- package/lib/mobx.js +1170 -1173
- package/lib/mobx.js.flow +175 -160
- package/lib/mobx.min.js +1 -4
- package/lib/mobx.module.js +1115 -1118
- package/lib/mobx.umd.js +4252 -4441
- package/lib/mobx.umd.min.js +1 -4
- package/lib/types/observableset.d.ts +1 -1
- package/package.json +48 -42
- package/lib/mobx.min.js.map +0 -1
- package/lib/mobx.umd.min.js.map +0 -1
package/lib/mobx.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** MobX - (c) Michel Weststrate 2015
|
|
1
|
+
/** MobX - (c) Michel Weststrate 2015 - 2018 - MIT Licensed */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -19,9 +19,12 @@ and limitations under the License.
|
|
|
19
19
|
***************************************************************************** */
|
|
20
20
|
/* global Reflect, Promise */
|
|
21
21
|
|
|
22
|
-
var extendStatics =
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
var extendStatics = function(d, b) {
|
|
23
|
+
extendStatics = Object.setPrototypeOf ||
|
|
24
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
25
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
26
|
+
return extendStatics(d, b);
|
|
27
|
+
};
|
|
25
28
|
|
|
26
29
|
function __extends(d, b) {
|
|
27
30
|
extendStatics(d, b);
|
|
@@ -29,30 +32,17 @@ function __extends(d, b) {
|
|
|
29
32
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
var __assign =
|
|
33
|
-
|
|
34
|
-
s = arguments
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
var __assign = function() {
|
|
36
|
+
__assign = Object.assign || function __assign(t) {
|
|
37
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
38
|
+
s = arguments[i];
|
|
39
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
40
|
+
}
|
|
41
|
+
return t;
|
|
42
|
+
};
|
|
43
|
+
return __assign.apply(this, arguments);
|
|
38
44
|
};
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
46
|
function __read(o, n) {
|
|
57
47
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
58
48
|
if (!m) return o;
|
|
@@ -76,35 +66,35 @@ function __spread() {
|
|
|
76
66
|
return ar;
|
|
77
67
|
}
|
|
78
68
|
|
|
79
|
-
var OBFUSCATED_ERROR
|
|
80
|
-
var EMPTY_ARRAY
|
|
81
|
-
Object.freeze(EMPTY_ARRAY
|
|
82
|
-
var EMPTY_OBJECT
|
|
83
|
-
Object.freeze(EMPTY_OBJECT
|
|
84
|
-
function getGlobal
|
|
69
|
+
var OBFUSCATED_ERROR = "An invariant failed, however the error is obfuscated because this is an production build.";
|
|
70
|
+
var EMPTY_ARRAY = [];
|
|
71
|
+
Object.freeze(EMPTY_ARRAY);
|
|
72
|
+
var EMPTY_OBJECT = {};
|
|
73
|
+
Object.freeze(EMPTY_OBJECT);
|
|
74
|
+
function getGlobal() {
|
|
85
75
|
return typeof window !== "undefined" ? window : global;
|
|
86
76
|
}
|
|
87
|
-
function getNextId
|
|
88
|
-
return ++globalState
|
|
77
|
+
function getNextId() {
|
|
78
|
+
return ++globalState.mobxGuid;
|
|
89
79
|
}
|
|
90
|
-
function fail
|
|
91
|
-
invariant
|
|
80
|
+
function fail(message) {
|
|
81
|
+
invariant(false, message);
|
|
92
82
|
throw "X"; // unreachable
|
|
93
83
|
}
|
|
94
|
-
function invariant
|
|
84
|
+
function invariant(check, message) {
|
|
95
85
|
if (!check)
|
|
96
|
-
throw new Error("[mobx] " + (message || OBFUSCATED_ERROR
|
|
86
|
+
throw new Error("[mobx] " + (message || OBFUSCATED_ERROR));
|
|
97
87
|
}
|
|
98
88
|
/**
|
|
99
89
|
* Prints a deprecation message, but only one time.
|
|
100
90
|
* Returns false if the deprecated message was already printed before
|
|
101
91
|
*/
|
|
102
92
|
var deprecatedMessages = [];
|
|
103
|
-
function deprecated
|
|
93
|
+
function deprecated(msg, thing) {
|
|
104
94
|
if (process.env.NODE_ENV === "production")
|
|
105
95
|
return false;
|
|
106
96
|
if (thing) {
|
|
107
|
-
return deprecated
|
|
97
|
+
return deprecated("'" + msg + "', use '" + thing + "' instead.");
|
|
108
98
|
}
|
|
109
99
|
if (deprecatedMessages.indexOf(msg) !== -1)
|
|
110
100
|
return false;
|
|
@@ -115,7 +105,7 @@ function deprecated$$1(msg, thing) {
|
|
|
115
105
|
/**
|
|
116
106
|
* Makes sure that the provided function is invoked at most once.
|
|
117
107
|
*/
|
|
118
|
-
function once
|
|
108
|
+
function once(func) {
|
|
119
109
|
var invoked = false;
|
|
120
110
|
return function () {
|
|
121
111
|
if (invoked)
|
|
@@ -124,8 +114,8 @@ function once$$1(func) {
|
|
|
124
114
|
return func.apply(this, arguments);
|
|
125
115
|
};
|
|
126
116
|
}
|
|
127
|
-
var noop
|
|
128
|
-
function unique
|
|
117
|
+
var noop = function () { };
|
|
118
|
+
function unique(list) {
|
|
129
119
|
var res = [];
|
|
130
120
|
list.forEach(function (item) {
|
|
131
121
|
if (res.indexOf(item) === -1)
|
|
@@ -133,21 +123,21 @@ function unique$$1(list) {
|
|
|
133
123
|
});
|
|
134
124
|
return res;
|
|
135
125
|
}
|
|
136
|
-
function isObject
|
|
126
|
+
function isObject(value) {
|
|
137
127
|
return value !== null && typeof value === "object";
|
|
138
128
|
}
|
|
139
|
-
function isPlainObject
|
|
129
|
+
function isPlainObject(value) {
|
|
140
130
|
if (value === null || typeof value !== "object")
|
|
141
131
|
return false;
|
|
142
132
|
var proto = Object.getPrototypeOf(value);
|
|
143
133
|
return proto === Object.prototype || proto === null;
|
|
144
134
|
}
|
|
145
|
-
function makeNonEnumerable
|
|
135
|
+
function makeNonEnumerable(object, propNames) {
|
|
146
136
|
for (var i = 0; i < propNames.length; i++) {
|
|
147
|
-
addHiddenProp
|
|
137
|
+
addHiddenProp(object, propNames[i], object[propNames[i]]);
|
|
148
138
|
}
|
|
149
139
|
}
|
|
150
|
-
function addHiddenProp
|
|
140
|
+
function addHiddenProp(object, propName, value) {
|
|
151
141
|
Object.defineProperty(object, propName, {
|
|
152
142
|
enumerable: false,
|
|
153
143
|
writable: true,
|
|
@@ -155,7 +145,7 @@ function addHiddenProp$$1(object, propName, value) {
|
|
|
155
145
|
value: value
|
|
156
146
|
});
|
|
157
147
|
}
|
|
158
|
-
function addHiddenFinalProp
|
|
148
|
+
function addHiddenFinalProp(object, propName, value) {
|
|
159
149
|
Object.defineProperty(object, propName, {
|
|
160
150
|
enumerable: false,
|
|
161
151
|
writable: false,
|
|
@@ -163,52 +153,52 @@ function addHiddenFinalProp$$1(object, propName, value) {
|
|
|
163
153
|
value: value
|
|
164
154
|
});
|
|
165
155
|
}
|
|
166
|
-
function isPropertyConfigurable
|
|
156
|
+
function isPropertyConfigurable(object, prop) {
|
|
167
157
|
var descriptor = Object.getOwnPropertyDescriptor(object, prop);
|
|
168
158
|
return !descriptor || (descriptor.configurable !== false && descriptor.writable !== false);
|
|
169
159
|
}
|
|
170
|
-
function assertPropertyConfigurable
|
|
171
|
-
if (process.env.NODE_ENV !== "production" && !isPropertyConfigurable
|
|
172
|
-
fail
|
|
160
|
+
function assertPropertyConfigurable(object, prop) {
|
|
161
|
+
if (process.env.NODE_ENV !== "production" && !isPropertyConfigurable(object, prop))
|
|
162
|
+
fail("Cannot make property '" + prop + "' observable, it is not configurable and writable in the target object");
|
|
173
163
|
}
|
|
174
|
-
function createInstanceofPredicate
|
|
164
|
+
function createInstanceofPredicate(name, clazz) {
|
|
175
165
|
var propName = "isMobX" + name;
|
|
176
166
|
clazz.prototype[propName] = true;
|
|
177
167
|
return function (x) {
|
|
178
|
-
return isObject
|
|
168
|
+
return isObject(x) && x[propName] === true;
|
|
179
169
|
};
|
|
180
170
|
}
|
|
181
|
-
function areBothNaN
|
|
171
|
+
function areBothNaN(a, b) {
|
|
182
172
|
return typeof a === "number" && typeof b === "number" && isNaN(a) && isNaN(b);
|
|
183
173
|
}
|
|
184
174
|
/**
|
|
185
175
|
* Returns whether the argument is an array, disregarding observability.
|
|
186
176
|
*/
|
|
187
|
-
function isArrayLike
|
|
188
|
-
return Array.isArray(x) || isObservableArray
|
|
177
|
+
function isArrayLike(x) {
|
|
178
|
+
return Array.isArray(x) || isObservableArray(x);
|
|
189
179
|
}
|
|
190
|
-
function isES6Map
|
|
191
|
-
if (getGlobal
|
|
180
|
+
function isES6Map(thing) {
|
|
181
|
+
if (getGlobal().Map !== undefined && thing instanceof getGlobal().Map)
|
|
192
182
|
return true;
|
|
193
183
|
return false;
|
|
194
184
|
}
|
|
195
|
-
function isES6Set
|
|
185
|
+
function isES6Set(thing) {
|
|
196
186
|
return thing instanceof Set;
|
|
197
187
|
}
|
|
198
|
-
function getMapLikeKeys
|
|
199
|
-
if (isPlainObject
|
|
188
|
+
function getMapLikeKeys(map) {
|
|
189
|
+
if (isPlainObject(map))
|
|
200
190
|
return Object.keys(map);
|
|
201
191
|
if (Array.isArray(map))
|
|
202
192
|
return map.map(function (_a) {
|
|
203
193
|
var _b = __read(_a, 1), key = _b[0];
|
|
204
194
|
return key;
|
|
205
195
|
});
|
|
206
|
-
if (isES6Map
|
|
207
|
-
return iteratorToArray
|
|
208
|
-
return fail
|
|
196
|
+
if (isES6Map(map) || isObservableMap(map))
|
|
197
|
+
return iteratorToArray(map.keys());
|
|
198
|
+
return fail("Cannot get keys from '" + map + "'");
|
|
209
199
|
}
|
|
210
200
|
// use Array.from in Mobx 5
|
|
211
|
-
function iteratorToArray
|
|
201
|
+
function iteratorToArray(it) {
|
|
212
202
|
var res = [];
|
|
213
203
|
while (true) {
|
|
214
204
|
var r = it.next();
|
|
@@ -218,26 +208,25 @@ function iteratorToArray$$1(it) {
|
|
|
218
208
|
}
|
|
219
209
|
return res;
|
|
220
210
|
}
|
|
221
|
-
function primitiveSymbol
|
|
211
|
+
function primitiveSymbol() {
|
|
222
212
|
// es-disable-next-line
|
|
223
213
|
return (typeof Symbol === "function" && Symbol.toPrimitive) || "@@toPrimitive";
|
|
224
214
|
}
|
|
225
|
-
function toPrimitive
|
|
215
|
+
function toPrimitive(value) {
|
|
226
216
|
return value === null ? null : typeof value === "object" ? "" + value : value;
|
|
227
217
|
}
|
|
228
218
|
|
|
229
|
-
function iteratorSymbol
|
|
219
|
+
function iteratorSymbol() {
|
|
230
220
|
return (typeof Symbol === "function" && Symbol.iterator) || "@@iterator";
|
|
231
221
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
addHiddenFinalProp$$1(prototType, iteratorSymbol$$1(), iteratorFactory);
|
|
222
|
+
function declareIterator(prototType, iteratorFactory) {
|
|
223
|
+
addHiddenFinalProp(prototType, iteratorSymbol(), iteratorFactory);
|
|
235
224
|
}
|
|
236
|
-
function makeIterable
|
|
237
|
-
iterator[iteratorSymbol
|
|
225
|
+
function makeIterable(iterator) {
|
|
226
|
+
iterator[iteratorSymbol()] = self;
|
|
238
227
|
return iterator;
|
|
239
228
|
}
|
|
240
|
-
function toStringTagSymbol
|
|
229
|
+
function toStringTagSymbol() {
|
|
241
230
|
return (typeof Symbol === "function" && Symbol.toStringTag) || "@@toStringTag";
|
|
242
231
|
}
|
|
243
232
|
function self() {
|
|
@@ -250,13 +239,13 @@ function self() {
|
|
|
250
239
|
* 1) detect when they are being _used_ and report this (using reportObserved). This allows mobx to make the connection between running functions and the data they used
|
|
251
240
|
* 2) they should notify mobx whenever they have _changed_. This way mobx can re-run any functions (derivations) that are using this atom.
|
|
252
241
|
*/
|
|
253
|
-
var Atom
|
|
242
|
+
var Atom = /** @class */ (function () {
|
|
254
243
|
/**
|
|
255
244
|
* Create a new atom. For debugging purposes it is recommended to give it a name.
|
|
256
245
|
* The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
|
|
257
246
|
*/
|
|
258
|
-
function Atom
|
|
259
|
-
if (name === void 0) { name = "Atom@" + getNextId
|
|
247
|
+
function Atom(name) {
|
|
248
|
+
if (name === void 0) { name = "Atom@" + getNextId(); }
|
|
260
249
|
this.name = name;
|
|
261
250
|
this.isPendingUnobservation = false; // for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
|
|
262
251
|
this.isBeingObserved = false;
|
|
@@ -266,39 +255,39 @@ var Atom$$1 = /** @class */ (function () {
|
|
|
266
255
|
this.lastAccessedBy = 0;
|
|
267
256
|
this.lowestObserverState = exports.IDerivationState.NOT_TRACKING;
|
|
268
257
|
}
|
|
269
|
-
Atom
|
|
258
|
+
Atom.prototype.onBecomeUnobserved = function () {
|
|
270
259
|
// noop
|
|
271
260
|
};
|
|
272
|
-
Atom
|
|
261
|
+
Atom.prototype.onBecomeObserved = function () {
|
|
273
262
|
/* noop */
|
|
274
263
|
};
|
|
275
264
|
/**
|
|
276
265
|
* Invoke this method to notify mobx that your atom has been used somehow.
|
|
277
266
|
* Returns true if there is currently a reactive context.
|
|
278
267
|
*/
|
|
279
|
-
Atom
|
|
280
|
-
return reportObserved
|
|
268
|
+
Atom.prototype.reportObserved = function () {
|
|
269
|
+
return reportObserved(this);
|
|
281
270
|
};
|
|
282
271
|
/**
|
|
283
272
|
* Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
|
|
284
273
|
*/
|
|
285
|
-
Atom
|
|
286
|
-
startBatch
|
|
287
|
-
propagateChanged
|
|
288
|
-
endBatch
|
|
274
|
+
Atom.prototype.reportChanged = function () {
|
|
275
|
+
startBatch();
|
|
276
|
+
propagateChanged(this);
|
|
277
|
+
endBatch();
|
|
289
278
|
};
|
|
290
|
-
Atom
|
|
279
|
+
Atom.prototype.toString = function () {
|
|
291
280
|
return this.name;
|
|
292
281
|
};
|
|
293
|
-
return Atom
|
|
282
|
+
return Atom;
|
|
294
283
|
}());
|
|
295
|
-
var isAtom
|
|
296
|
-
function createAtom
|
|
297
|
-
if (onBecomeObservedHandler === void 0) { onBecomeObservedHandler = noop
|
|
298
|
-
if (onBecomeUnobservedHandler === void 0) { onBecomeUnobservedHandler = noop
|
|
299
|
-
var atom = new Atom
|
|
300
|
-
onBecomeObserved
|
|
301
|
-
onBecomeUnobserved
|
|
284
|
+
var isAtom = createInstanceofPredicate("Atom", Atom);
|
|
285
|
+
function createAtom(name, onBecomeObservedHandler, onBecomeUnobservedHandler) {
|
|
286
|
+
if (onBecomeObservedHandler === void 0) { onBecomeObservedHandler = noop; }
|
|
287
|
+
if (onBecomeUnobservedHandler === void 0) { onBecomeUnobservedHandler = noop; }
|
|
288
|
+
var atom = new Atom(name);
|
|
289
|
+
onBecomeObserved(atom, onBecomeObservedHandler);
|
|
290
|
+
onBecomeUnobserved(atom, onBecomeUnobservedHandler);
|
|
302
291
|
return atom;
|
|
303
292
|
}
|
|
304
293
|
|
|
@@ -306,12 +295,12 @@ function identityComparer(a, b) {
|
|
|
306
295
|
return a === b;
|
|
307
296
|
}
|
|
308
297
|
function structuralComparer(a, b) {
|
|
309
|
-
return deepEqual
|
|
298
|
+
return deepEqual(a, b);
|
|
310
299
|
}
|
|
311
300
|
function defaultComparer(a, b) {
|
|
312
|
-
return areBothNaN
|
|
301
|
+
return areBothNaN(a, b) || identityComparer(a, b);
|
|
313
302
|
}
|
|
314
|
-
var comparer
|
|
303
|
+
var comparer = {
|
|
315
304
|
identity: identityComparer,
|
|
316
305
|
structural: structuralComparer,
|
|
317
306
|
default: defaultComparer
|
|
@@ -326,31 +315,31 @@ function createPropertyInitializerDescriptor(prop, enumerable) {
|
|
|
326
315
|
configurable: true,
|
|
327
316
|
enumerable: enumerable,
|
|
328
317
|
get: function () {
|
|
329
|
-
initializeInstance
|
|
318
|
+
initializeInstance(this);
|
|
330
319
|
return this[prop];
|
|
331
320
|
},
|
|
332
321
|
set: function (value) {
|
|
333
|
-
initializeInstance
|
|
322
|
+
initializeInstance(this);
|
|
334
323
|
this[prop] = value;
|
|
335
324
|
}
|
|
336
325
|
}));
|
|
337
326
|
}
|
|
338
|
-
function initializeInstance
|
|
327
|
+
function initializeInstance(target) {
|
|
339
328
|
if (target.__mobxDidRunLazyInitializers === true)
|
|
340
329
|
return;
|
|
341
330
|
var decorators = target.__mobxDecorators;
|
|
342
331
|
if (decorators) {
|
|
343
|
-
addHiddenProp
|
|
332
|
+
addHiddenProp(target, "__mobxDidRunLazyInitializers", true);
|
|
344
333
|
for (var key in decorators) {
|
|
345
334
|
var d = decorators[key];
|
|
346
335
|
d.propertyCreator(target, d.prop, d.descriptor, d.decoratorTarget, d.decoratorArguments);
|
|
347
336
|
}
|
|
348
337
|
}
|
|
349
338
|
}
|
|
350
|
-
function createPropDecorator
|
|
339
|
+
function createPropDecorator(propertyInitiallyEnumerable, propertyCreator) {
|
|
351
340
|
return function decoratorFactory() {
|
|
352
341
|
var decoratorArguments;
|
|
353
|
-
var decorator = function decorate
|
|
342
|
+
var decorator = function decorate(target, prop, descriptor, applyImmediately
|
|
354
343
|
// This is a special parameter to signal the direct application of a decorator, allow extendObservable to skip the entire type decoration part,
|
|
355
344
|
// as the instance to apply the decorator to equals the target
|
|
356
345
|
) {
|
|
@@ -358,11 +347,11 @@ function createPropDecorator$$1(propertyInitiallyEnumerable, propertyCreator) {
|
|
|
358
347
|
propertyCreator(target, prop, descriptor, target, decoratorArguments);
|
|
359
348
|
return null;
|
|
360
349
|
}
|
|
361
|
-
if (process.env.NODE_ENV !== "production" && !quacksLikeADecorator
|
|
362
|
-
fail
|
|
350
|
+
if (process.env.NODE_ENV !== "production" && !quacksLikeADecorator(arguments))
|
|
351
|
+
fail("This function is a decorator, but it wasn't invoked like a decorator");
|
|
363
352
|
if (!Object.prototype.hasOwnProperty.call(target, "__mobxDecorators")) {
|
|
364
353
|
var inheritedDecorators = target.__mobxDecorators;
|
|
365
|
-
addHiddenProp
|
|
354
|
+
addHiddenProp(target, "__mobxDecorators", __assign({}, inheritedDecorators));
|
|
366
355
|
}
|
|
367
356
|
target.__mobxDecorators[prop] = {
|
|
368
357
|
prop: prop,
|
|
@@ -373,9 +362,9 @@ function createPropDecorator$$1(propertyInitiallyEnumerable, propertyCreator) {
|
|
|
373
362
|
};
|
|
374
363
|
return createPropertyInitializerDescriptor(prop, propertyInitiallyEnumerable);
|
|
375
364
|
};
|
|
376
|
-
if (quacksLikeADecorator
|
|
365
|
+
if (quacksLikeADecorator(arguments)) {
|
|
377
366
|
// @decorator
|
|
378
|
-
decoratorArguments = EMPTY_ARRAY
|
|
367
|
+
decoratorArguments = EMPTY_ARRAY;
|
|
379
368
|
return decorator.apply(null, arguments);
|
|
380
369
|
}
|
|
381
370
|
else {
|
|
@@ -385,65 +374,65 @@ function createPropDecorator$$1(propertyInitiallyEnumerable, propertyCreator) {
|
|
|
385
374
|
}
|
|
386
375
|
};
|
|
387
376
|
}
|
|
388
|
-
function quacksLikeADecorator
|
|
377
|
+
function quacksLikeADecorator(args) {
|
|
389
378
|
return (((args.length === 2 || args.length === 3) && typeof args[1] === "string") ||
|
|
390
379
|
(args.length === 4 && args[3] === true));
|
|
391
380
|
}
|
|
392
381
|
|
|
393
|
-
function deepEnhancer
|
|
382
|
+
function deepEnhancer(v, _, name) {
|
|
394
383
|
// it is an observable already, done
|
|
395
|
-
if (isObservable
|
|
384
|
+
if (isObservable(v))
|
|
396
385
|
return v;
|
|
397
386
|
// something that can be converted and mutated?
|
|
398
387
|
if (Array.isArray(v))
|
|
399
|
-
return observable
|
|
400
|
-
if (isPlainObject
|
|
401
|
-
return observable
|
|
402
|
-
if (isES6Map
|
|
403
|
-
return observable
|
|
404
|
-
if (isES6Set
|
|
405
|
-
return observable
|
|
388
|
+
return observable.array(v, { name: name });
|
|
389
|
+
if (isPlainObject(v))
|
|
390
|
+
return observable.object(v, undefined, { name: name });
|
|
391
|
+
if (isES6Map(v))
|
|
392
|
+
return observable.map(v, { name: name });
|
|
393
|
+
if (isES6Set(v))
|
|
394
|
+
return observable.set(v, { name: name });
|
|
406
395
|
return v;
|
|
407
396
|
}
|
|
408
|
-
function shallowEnhancer
|
|
397
|
+
function shallowEnhancer(v, _, name) {
|
|
409
398
|
if (v === undefined || v === null)
|
|
410
399
|
return v;
|
|
411
|
-
if (isObservableObject
|
|
400
|
+
if (isObservableObject(v) || isObservableArray(v) || isObservableMap(v) || isObservableSet(v))
|
|
412
401
|
return v;
|
|
413
402
|
if (Array.isArray(v))
|
|
414
|
-
return observable
|
|
415
|
-
if (isPlainObject
|
|
416
|
-
return observable
|
|
417
|
-
if (isES6Map
|
|
418
|
-
return observable
|
|
419
|
-
if (isES6Set
|
|
420
|
-
return observable
|
|
421
|
-
return fail
|
|
403
|
+
return observable.array(v, { name: name, deep: false });
|
|
404
|
+
if (isPlainObject(v))
|
|
405
|
+
return observable.object(v, undefined, { name: name, deep: false });
|
|
406
|
+
if (isES6Map(v))
|
|
407
|
+
return observable.map(v, { name: name, deep: false });
|
|
408
|
+
if (isES6Set(v))
|
|
409
|
+
return observable.set(v, { name: name, deep: false });
|
|
410
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
422
411
|
"The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
|
|
423
412
|
}
|
|
424
|
-
function referenceEnhancer
|
|
413
|
+
function referenceEnhancer(newValue) {
|
|
425
414
|
// never turn into an observable
|
|
426
415
|
return newValue;
|
|
427
416
|
}
|
|
428
|
-
function refStructEnhancer
|
|
429
|
-
if (process.env.NODE_ENV !== "production" && isObservable
|
|
417
|
+
function refStructEnhancer(v, oldValue, name) {
|
|
418
|
+
if (process.env.NODE_ENV !== "production" && isObservable(v))
|
|
430
419
|
throw "observable.struct should not be used with observable values";
|
|
431
|
-
if (deepEqual
|
|
420
|
+
if (deepEqual(v, oldValue))
|
|
432
421
|
return oldValue;
|
|
433
422
|
return v;
|
|
434
423
|
}
|
|
435
424
|
|
|
436
|
-
function createDecoratorForEnhancer
|
|
437
|
-
var decorator = createPropDecorator
|
|
425
|
+
function createDecoratorForEnhancer(enhancer) {
|
|
426
|
+
var decorator = createPropDecorator(true, function (target, propertyName, descriptor, _decoratorTarget, decoratorArgs) {
|
|
438
427
|
if (process.env.NODE_ENV !== "production") {
|
|
439
|
-
invariant
|
|
428
|
+
invariant(!descriptor || !descriptor.get, "@observable cannot be used on getter (property \"" + propertyName + "\"), use @computed instead.");
|
|
440
429
|
}
|
|
441
430
|
var initialValue = descriptor
|
|
442
431
|
? descriptor.initializer
|
|
443
432
|
? descriptor.initializer.call(target)
|
|
444
433
|
: descriptor.value
|
|
445
434
|
: undefined;
|
|
446
|
-
defineObservableProperty
|
|
435
|
+
defineObservableProperty(target, propertyName, initialValue, enhancer);
|
|
447
436
|
});
|
|
448
437
|
var res =
|
|
449
438
|
// Extra process checks, as this happens during module initialization
|
|
@@ -452,7 +441,7 @@ function createDecoratorForEnhancer$$1(enhancer) {
|
|
|
452
441
|
// This wrapper function is just to detect illegal decorator invocations, deprecate in a next version
|
|
453
442
|
// and simply return the created prop decorator
|
|
454
443
|
if (arguments.length < 2)
|
|
455
|
-
return fail
|
|
444
|
+
return fail("Incorrect decorator invocation. @observable decorator doesn't expect any arguments");
|
|
456
445
|
return decorator.apply(null, arguments);
|
|
457
446
|
}
|
|
458
447
|
: decorator;
|
|
@@ -462,30 +451,30 @@ function createDecoratorForEnhancer$$1(enhancer) {
|
|
|
462
451
|
|
|
463
452
|
// Predefined bags of create observable options, to avoid allocating temporarily option objects
|
|
464
453
|
// in the majority of cases
|
|
465
|
-
var defaultCreateObservableOptions
|
|
454
|
+
var defaultCreateObservableOptions = {
|
|
466
455
|
deep: true,
|
|
467
456
|
name: undefined,
|
|
468
457
|
defaultDecorator: undefined
|
|
469
458
|
};
|
|
470
|
-
var shallowCreateObservableOptions
|
|
459
|
+
var shallowCreateObservableOptions = {
|
|
471
460
|
deep: false,
|
|
472
461
|
name: undefined,
|
|
473
462
|
defaultDecorator: undefined
|
|
474
463
|
};
|
|
475
|
-
Object.freeze(defaultCreateObservableOptions
|
|
476
|
-
Object.freeze(shallowCreateObservableOptions
|
|
464
|
+
Object.freeze(defaultCreateObservableOptions);
|
|
465
|
+
Object.freeze(shallowCreateObservableOptions);
|
|
477
466
|
function assertValidOption(key) {
|
|
478
467
|
if (!/^(deep|name|equals|defaultDecorator)$/.test(key))
|
|
479
|
-
fail
|
|
468
|
+
fail("invalid option for (extend)observable: " + key);
|
|
480
469
|
}
|
|
481
|
-
function asCreateObservableOptions
|
|
470
|
+
function asCreateObservableOptions(thing) {
|
|
482
471
|
if (thing === null || thing === undefined)
|
|
483
|
-
return defaultCreateObservableOptions
|
|
472
|
+
return defaultCreateObservableOptions;
|
|
484
473
|
if (typeof thing === "string")
|
|
485
474
|
return { name: thing, deep: true };
|
|
486
475
|
if (process.env.NODE_ENV !== "production") {
|
|
487
476
|
if (typeof thing !== "object")
|
|
488
|
-
return fail
|
|
477
|
+
return fail("expected options object");
|
|
489
478
|
Object.keys(thing).forEach(assertValidOption);
|
|
490
479
|
}
|
|
491
480
|
return thing;
|
|
@@ -494,13 +483,13 @@ function getEnhancerFromOptions(options) {
|
|
|
494
483
|
return options.defaultDecorator
|
|
495
484
|
? options.defaultDecorator.enhancer
|
|
496
485
|
: options.deep === false
|
|
497
|
-
? referenceEnhancer
|
|
498
|
-
: deepEnhancer
|
|
486
|
+
? referenceEnhancer
|
|
487
|
+
: deepEnhancer;
|
|
499
488
|
}
|
|
500
|
-
var deepDecorator
|
|
501
|
-
var shallowDecorator = createDecoratorForEnhancer
|
|
502
|
-
var refDecorator
|
|
503
|
-
var refStructDecorator = createDecoratorForEnhancer
|
|
489
|
+
var deepDecorator = createDecoratorForEnhancer(deepEnhancer);
|
|
490
|
+
var shallowDecorator = createDecoratorForEnhancer(shallowEnhancer);
|
|
491
|
+
var refDecorator = createDecoratorForEnhancer(referenceEnhancer);
|
|
492
|
+
var refStructDecorator = createDecoratorForEnhancer(refStructEnhancer);
|
|
504
493
|
/**
|
|
505
494
|
* Turns an object, array or function into a reactive structure.
|
|
506
495
|
* @param v the value which should become observable.
|
|
@@ -508,145 +497,145 @@ var refStructDecorator = createDecoratorForEnhancer$$1(refStructEnhancer$$1);
|
|
|
508
497
|
function createObservable(v, arg2, arg3) {
|
|
509
498
|
// @observable someProp;
|
|
510
499
|
if (typeof arguments[1] === "string") {
|
|
511
|
-
return deepDecorator
|
|
500
|
+
return deepDecorator.apply(null, arguments);
|
|
512
501
|
}
|
|
513
502
|
// it is an observable already, done
|
|
514
|
-
if (isObservable
|
|
503
|
+
if (isObservable(v))
|
|
515
504
|
return v;
|
|
516
505
|
// something that can be converted and mutated?
|
|
517
|
-
var res = isPlainObject
|
|
518
|
-
? observable
|
|
506
|
+
var res = isPlainObject(v)
|
|
507
|
+
? observable.object(v, arg2, arg3)
|
|
519
508
|
: Array.isArray(v)
|
|
520
|
-
? observable
|
|
521
|
-
: isES6Map
|
|
522
|
-
? observable
|
|
523
|
-
: isES6Set
|
|
524
|
-
? observable
|
|
509
|
+
? observable.array(v, arg2)
|
|
510
|
+
: isES6Map(v)
|
|
511
|
+
? observable.map(v, arg2)
|
|
512
|
+
: isES6Set(v)
|
|
513
|
+
? observable.set(v, arg2)
|
|
525
514
|
: v;
|
|
526
515
|
// this value could be converted to a new observable data structure, return it
|
|
527
516
|
if (res !== v)
|
|
528
517
|
return res;
|
|
529
518
|
// otherwise, just box it
|
|
530
|
-
fail
|
|
519
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
531
520
|
"The provided value could not be converted into an observable. If you want just create an observable reference to the object use 'observable.box(value)'");
|
|
532
521
|
}
|
|
533
522
|
var observableFactories = {
|
|
534
523
|
box: function (value, options) {
|
|
535
524
|
if (arguments.length > 2)
|
|
536
525
|
incorrectlyUsedAsDecorator("box");
|
|
537
|
-
var o = asCreateObservableOptions
|
|
538
|
-
return new ObservableValue
|
|
526
|
+
var o = asCreateObservableOptions(options);
|
|
527
|
+
return new ObservableValue(value, getEnhancerFromOptions(o), o.name, true, o.equals);
|
|
539
528
|
},
|
|
540
529
|
shallowBox: function (value, name) {
|
|
541
530
|
if (arguments.length > 2)
|
|
542
531
|
incorrectlyUsedAsDecorator("shallowBox");
|
|
543
|
-
deprecated
|
|
544
|
-
return observable
|
|
532
|
+
deprecated("observable.shallowBox", "observable.box(value, { deep: false })");
|
|
533
|
+
return observable.box(value, { name: name, deep: false });
|
|
545
534
|
},
|
|
546
535
|
array: function (initialValues, options) {
|
|
547
536
|
if (arguments.length > 2)
|
|
548
537
|
incorrectlyUsedAsDecorator("array");
|
|
549
|
-
var o = asCreateObservableOptions
|
|
550
|
-
return new ObservableArray
|
|
538
|
+
var o = asCreateObservableOptions(options);
|
|
539
|
+
return new ObservableArray(initialValues, getEnhancerFromOptions(o), o.name);
|
|
551
540
|
},
|
|
552
541
|
shallowArray: function (initialValues, name) {
|
|
553
542
|
if (arguments.length > 2)
|
|
554
543
|
incorrectlyUsedAsDecorator("shallowArray");
|
|
555
|
-
deprecated
|
|
556
|
-
return observable
|
|
544
|
+
deprecated("observable.shallowArray", "observable.array(values, { deep: false })");
|
|
545
|
+
return observable.array(initialValues, { name: name, deep: false });
|
|
557
546
|
},
|
|
558
547
|
map: function (initialValues, options) {
|
|
559
548
|
if (arguments.length > 2)
|
|
560
549
|
incorrectlyUsedAsDecorator("map");
|
|
561
|
-
var o = asCreateObservableOptions
|
|
562
|
-
return new ObservableMap
|
|
550
|
+
var o = asCreateObservableOptions(options);
|
|
551
|
+
return new ObservableMap(initialValues, getEnhancerFromOptions(o), o.name);
|
|
563
552
|
},
|
|
564
553
|
shallowMap: function (initialValues, name) {
|
|
565
554
|
if (arguments.length > 2)
|
|
566
555
|
incorrectlyUsedAsDecorator("shallowMap");
|
|
567
|
-
deprecated
|
|
568
|
-
return observable
|
|
556
|
+
deprecated("observable.shallowMap", "observable.map(values, { deep: false })");
|
|
557
|
+
return observable.map(initialValues, { name: name, deep: false });
|
|
569
558
|
},
|
|
570
559
|
set: function (initialValues, options) {
|
|
571
560
|
if (arguments.length > 2)
|
|
572
561
|
incorrectlyUsedAsDecorator("set");
|
|
573
|
-
var o = asCreateObservableOptions
|
|
574
|
-
return new ObservableSet
|
|
562
|
+
var o = asCreateObservableOptions(options);
|
|
563
|
+
return new ObservableSet(initialValues, getEnhancerFromOptions(o), o.name);
|
|
575
564
|
},
|
|
576
565
|
object: function (props, decorators, options) {
|
|
577
566
|
if (typeof arguments[1] === "string")
|
|
578
567
|
incorrectlyUsedAsDecorator("object");
|
|
579
|
-
var o = asCreateObservableOptions
|
|
580
|
-
return extendObservable
|
|
568
|
+
var o = asCreateObservableOptions(options);
|
|
569
|
+
return extendObservable({}, props, decorators, o);
|
|
581
570
|
},
|
|
582
571
|
shallowObject: function (props, name) {
|
|
583
572
|
if (typeof arguments[1] === "string")
|
|
584
573
|
incorrectlyUsedAsDecorator("shallowObject");
|
|
585
|
-
deprecated
|
|
586
|
-
return observable
|
|
574
|
+
deprecated("observable.shallowObject", "observable.object(values, {}, { deep: false })");
|
|
575
|
+
return observable.object(props, {}, { name: name, deep: false });
|
|
587
576
|
},
|
|
588
|
-
ref: refDecorator
|
|
577
|
+
ref: refDecorator,
|
|
589
578
|
shallow: shallowDecorator,
|
|
590
|
-
deep: deepDecorator
|
|
579
|
+
deep: deepDecorator,
|
|
591
580
|
struct: refStructDecorator
|
|
592
581
|
};
|
|
593
|
-
var observable
|
|
582
|
+
var observable = createObservable;
|
|
594
583
|
// weird trick to keep our typings nicely with our funcs, and still extend the observable function
|
|
595
|
-
Object.keys(observableFactories).forEach(function (name) { return (observable
|
|
584
|
+
Object.keys(observableFactories).forEach(function (name) { return (observable[name] = observableFactories[name]); });
|
|
596
585
|
function incorrectlyUsedAsDecorator(methodName) {
|
|
597
|
-
fail
|
|
586
|
+
fail(
|
|
598
587
|
// process.env.NODE_ENV !== "production" &&
|
|
599
588
|
"Expected one or two arguments to observable." + methodName + ". Did you accidentally try to use observable." + methodName + " as decorator?");
|
|
600
589
|
}
|
|
601
590
|
|
|
602
|
-
var computedDecorator
|
|
603
|
-
var get
|
|
591
|
+
var computedDecorator = createPropDecorator(false, function (instance, propertyName, descriptor, decoratorTarget, decoratorArgs) {
|
|
592
|
+
var get = descriptor.get, set = descriptor.set; // initialValue is the descriptor for get / set props
|
|
604
593
|
// Optimization: faster on decorator target or instance? Assuming target
|
|
605
594
|
// Optimization: find out if declaring on instance isn't just faster. (also makes the property descriptor simpler). But, more memory usage..
|
|
606
595
|
// Forcing instance now, fixes hot reloadig issues on React Native:
|
|
607
596
|
var options = decoratorArgs[0] || {};
|
|
608
|
-
defineComputedProperty
|
|
597
|
+
defineComputedProperty(instance, propertyName, __assign({ get: get, set: set }, options));
|
|
609
598
|
});
|
|
610
|
-
var computedStructDecorator = computedDecorator
|
|
599
|
+
var computedStructDecorator = computedDecorator({ equals: comparer.structural });
|
|
611
600
|
/**
|
|
612
601
|
* Decorator for class properties: @computed get value() { return expr; }.
|
|
613
602
|
* For legacy purposes also invokable as ES5 observable created: `computed(() => expr)`;
|
|
614
603
|
*/
|
|
615
|
-
var computed
|
|
604
|
+
var computed = function computed(arg1, arg2, arg3) {
|
|
616
605
|
if (typeof arg2 === "string") {
|
|
617
606
|
// @computed
|
|
618
|
-
return computedDecorator
|
|
607
|
+
return computedDecorator.apply(null, arguments);
|
|
619
608
|
}
|
|
620
609
|
if (arg1 !== null && typeof arg1 === "object" && arguments.length === 1) {
|
|
621
610
|
// @computed({ options })
|
|
622
|
-
return computedDecorator
|
|
611
|
+
return computedDecorator.apply(null, arguments);
|
|
623
612
|
}
|
|
624
613
|
// computed(expr, options?)
|
|
625
614
|
if (process.env.NODE_ENV !== "production") {
|
|
626
|
-
invariant
|
|
627
|
-
invariant
|
|
615
|
+
invariant(typeof arg1 === "function", "First argument to `computed` should be an expression.");
|
|
616
|
+
invariant(arguments.length < 3, "Computed takes one or two arguments if used as function");
|
|
628
617
|
}
|
|
629
618
|
var opts = typeof arg2 === "object" ? arg2 : {};
|
|
630
619
|
opts.get = arg1;
|
|
631
620
|
opts.set = typeof arg2 === "function" ? arg2 : opts.set;
|
|
632
621
|
opts.name = opts.name || arg1.name || ""; /* for generated name */
|
|
633
|
-
return new ComputedValue
|
|
622
|
+
return new ComputedValue(opts);
|
|
634
623
|
};
|
|
635
|
-
computed
|
|
624
|
+
computed.struct = computedStructDecorator;
|
|
636
625
|
|
|
637
|
-
function createAction
|
|
626
|
+
function createAction(actionName, fn) {
|
|
638
627
|
if (process.env.NODE_ENV !== "production") {
|
|
639
|
-
invariant
|
|
628
|
+
invariant(typeof fn === "function", "`action` can only be invoked on functions");
|
|
640
629
|
if (typeof actionName !== "string" || !actionName)
|
|
641
|
-
fail
|
|
630
|
+
fail("actions should have valid names, got: '" + actionName + "'");
|
|
642
631
|
}
|
|
643
632
|
var res = function () {
|
|
644
|
-
return executeAction
|
|
633
|
+
return executeAction(actionName, fn, this, arguments);
|
|
645
634
|
};
|
|
646
635
|
res.isMobxAction = true;
|
|
647
636
|
return res;
|
|
648
637
|
}
|
|
649
|
-
function executeAction
|
|
638
|
+
function executeAction(actionName, fn, scope, args) {
|
|
650
639
|
var runInfo = startAction(actionName, fn, scope, args);
|
|
651
640
|
var shouldSupressReactionError = true;
|
|
652
641
|
try {
|
|
@@ -656,9 +645,9 @@ function executeAction$$1(actionName, fn, scope, args) {
|
|
|
656
645
|
}
|
|
657
646
|
finally {
|
|
658
647
|
if (shouldSupressReactionError) {
|
|
659
|
-
globalState
|
|
648
|
+
globalState.suppressReactionErrors = shouldSupressReactionError;
|
|
660
649
|
endAction(runInfo);
|
|
661
|
-
globalState
|
|
650
|
+
globalState.suppressReactionErrors = false;
|
|
662
651
|
}
|
|
663
652
|
else {
|
|
664
653
|
endAction(runInfo);
|
|
@@ -666,7 +655,7 @@ function executeAction$$1(actionName, fn, scope, args) {
|
|
|
666
655
|
}
|
|
667
656
|
}
|
|
668
657
|
function startAction(actionName, fn, scope, args) {
|
|
669
|
-
var notifySpy = isSpyEnabled
|
|
658
|
+
var notifySpy = isSpyEnabled() && !!actionName;
|
|
670
659
|
var startTime = 0;
|
|
671
660
|
if (notifySpy) {
|
|
672
661
|
startTime = Date.now();
|
|
@@ -675,16 +664,16 @@ function startAction(actionName, fn, scope, args) {
|
|
|
675
664
|
if (l > 0)
|
|
676
665
|
for (var i = 0; i < l; i++)
|
|
677
666
|
flattendArgs[i] = args[i];
|
|
678
|
-
spyReportStart
|
|
667
|
+
spyReportStart({
|
|
679
668
|
type: "action",
|
|
680
669
|
name: actionName,
|
|
681
670
|
object: scope,
|
|
682
671
|
arguments: flattendArgs
|
|
683
672
|
});
|
|
684
673
|
}
|
|
685
|
-
var prevDerivation = untrackedStart
|
|
686
|
-
startBatch
|
|
687
|
-
var prevAllowStateChanges = allowStateChangesStart
|
|
674
|
+
var prevDerivation = untrackedStart();
|
|
675
|
+
startBatch();
|
|
676
|
+
var prevAllowStateChanges = allowStateChangesStart(true);
|
|
688
677
|
return {
|
|
689
678
|
prevDerivation: prevDerivation,
|
|
690
679
|
prevAllowStateChanges: prevAllowStateChanges,
|
|
@@ -693,74 +682,74 @@ function startAction(actionName, fn, scope, args) {
|
|
|
693
682
|
};
|
|
694
683
|
}
|
|
695
684
|
function endAction(runInfo) {
|
|
696
|
-
allowStateChangesEnd
|
|
697
|
-
endBatch
|
|
698
|
-
untrackedEnd
|
|
685
|
+
allowStateChangesEnd(runInfo.prevAllowStateChanges);
|
|
686
|
+
endBatch();
|
|
687
|
+
untrackedEnd(runInfo.prevDerivation);
|
|
699
688
|
if (runInfo.notifySpy)
|
|
700
|
-
spyReportEnd
|
|
689
|
+
spyReportEnd({ time: Date.now() - runInfo.startTime });
|
|
701
690
|
}
|
|
702
|
-
function allowStateChanges
|
|
703
|
-
var prev = allowStateChangesStart
|
|
691
|
+
function allowStateChanges(allowStateChanges, func) {
|
|
692
|
+
var prev = allowStateChangesStart(allowStateChanges);
|
|
704
693
|
var res;
|
|
705
694
|
try {
|
|
706
695
|
res = func();
|
|
707
696
|
}
|
|
708
697
|
finally {
|
|
709
|
-
allowStateChangesEnd
|
|
698
|
+
allowStateChangesEnd(prev);
|
|
710
699
|
}
|
|
711
700
|
return res;
|
|
712
701
|
}
|
|
713
|
-
function allowStateChangesStart
|
|
714
|
-
var prev = globalState
|
|
715
|
-
globalState
|
|
702
|
+
function allowStateChangesStart(allowStateChanges) {
|
|
703
|
+
var prev = globalState.allowStateChanges;
|
|
704
|
+
globalState.allowStateChanges = allowStateChanges;
|
|
716
705
|
return prev;
|
|
717
706
|
}
|
|
718
|
-
function allowStateChangesEnd
|
|
719
|
-
globalState
|
|
707
|
+
function allowStateChangesEnd(prev) {
|
|
708
|
+
globalState.allowStateChanges = prev;
|
|
720
709
|
}
|
|
721
|
-
function allowStateChangesInsideComputed
|
|
722
|
-
var prev = globalState
|
|
723
|
-
globalState
|
|
710
|
+
function allowStateChangesInsideComputed(func) {
|
|
711
|
+
var prev = globalState.computationDepth;
|
|
712
|
+
globalState.computationDepth = 0;
|
|
724
713
|
var res;
|
|
725
714
|
try {
|
|
726
715
|
res = func();
|
|
727
716
|
}
|
|
728
717
|
finally {
|
|
729
|
-
globalState
|
|
718
|
+
globalState.computationDepth = prev;
|
|
730
719
|
}
|
|
731
720
|
return res;
|
|
732
721
|
}
|
|
733
722
|
|
|
734
|
-
var ObservableValue
|
|
735
|
-
__extends(ObservableValue
|
|
736
|
-
function ObservableValue
|
|
737
|
-
if (name === void 0) { name = "ObservableValue@" + getNextId
|
|
723
|
+
var ObservableValue = /** @class */ (function (_super) {
|
|
724
|
+
__extends(ObservableValue, _super);
|
|
725
|
+
function ObservableValue(value, enhancer, name, notifySpy, equals) {
|
|
726
|
+
if (name === void 0) { name = "ObservableValue@" + getNextId(); }
|
|
738
727
|
if (notifySpy === void 0) { notifySpy = true; }
|
|
739
|
-
if (equals === void 0) { equals = comparer
|
|
728
|
+
if (equals === void 0) { equals = comparer.default; }
|
|
740
729
|
var _this = _super.call(this, name) || this;
|
|
741
730
|
_this.enhancer = enhancer;
|
|
742
731
|
_this.name = name;
|
|
743
732
|
_this.equals = equals;
|
|
744
733
|
_this.hasUnreportedChange = false;
|
|
745
734
|
_this.value = enhancer(value, undefined, name);
|
|
746
|
-
if (notifySpy && isSpyEnabled
|
|
735
|
+
if (notifySpy && isSpyEnabled()) {
|
|
747
736
|
// only notify spy if this is a stand-alone observable
|
|
748
|
-
spyReport
|
|
737
|
+
spyReport({ type: "create", name: _this.name, newValue: "" + _this.value });
|
|
749
738
|
}
|
|
750
739
|
return _this;
|
|
751
740
|
}
|
|
752
|
-
ObservableValue
|
|
741
|
+
ObservableValue.prototype.dehanceValue = function (value) {
|
|
753
742
|
if (this.dehancer !== undefined)
|
|
754
743
|
return this.dehancer(value);
|
|
755
744
|
return value;
|
|
756
745
|
};
|
|
757
|
-
ObservableValue
|
|
746
|
+
ObservableValue.prototype.set = function (newValue) {
|
|
758
747
|
var oldValue = this.value;
|
|
759
748
|
newValue = this.prepareNewValue(newValue);
|
|
760
|
-
if (newValue !== globalState
|
|
761
|
-
var notifySpy = isSpyEnabled
|
|
749
|
+
if (newValue !== globalState.UNCHANGED) {
|
|
750
|
+
var notifySpy = isSpyEnabled();
|
|
762
751
|
if (notifySpy) {
|
|
763
|
-
spyReportStart
|
|
752
|
+
spyReportStart({
|
|
764
753
|
type: "update",
|
|
765
754
|
name: this.name,
|
|
766
755
|
newValue: newValue,
|
|
@@ -769,31 +758,31 @@ var ObservableValue$$1 = /** @class */ (function (_super) {
|
|
|
769
758
|
}
|
|
770
759
|
this.setNewValue(newValue);
|
|
771
760
|
if (notifySpy)
|
|
772
|
-
spyReportEnd
|
|
761
|
+
spyReportEnd();
|
|
773
762
|
}
|
|
774
763
|
};
|
|
775
|
-
ObservableValue
|
|
776
|
-
checkIfStateModificationsAreAllowed
|
|
777
|
-
if (hasInterceptors
|
|
778
|
-
var change = interceptChange
|
|
764
|
+
ObservableValue.prototype.prepareNewValue = function (newValue) {
|
|
765
|
+
checkIfStateModificationsAreAllowed(this);
|
|
766
|
+
if (hasInterceptors(this)) {
|
|
767
|
+
var change = interceptChange(this, {
|
|
779
768
|
object: this,
|
|
780
769
|
type: "update",
|
|
781
770
|
newValue: newValue
|
|
782
771
|
});
|
|
783
772
|
if (!change)
|
|
784
|
-
return globalState
|
|
773
|
+
return globalState.UNCHANGED;
|
|
785
774
|
newValue = change.newValue;
|
|
786
775
|
}
|
|
787
776
|
// apply modifier
|
|
788
777
|
newValue = this.enhancer(newValue, this.value, this.name);
|
|
789
|
-
return this.equals(this.value, newValue) ? globalState
|
|
778
|
+
return this.equals(this.value, newValue) ? globalState.UNCHANGED : newValue;
|
|
790
779
|
};
|
|
791
|
-
ObservableValue
|
|
780
|
+
ObservableValue.prototype.setNewValue = function (newValue) {
|
|
792
781
|
var oldValue = this.value;
|
|
793
782
|
this.value = newValue;
|
|
794
783
|
this.reportChanged();
|
|
795
|
-
if (hasListeners
|
|
796
|
-
notifyListeners
|
|
784
|
+
if (hasListeners(this)) {
|
|
785
|
+
notifyListeners(this, {
|
|
797
786
|
type: "update",
|
|
798
787
|
object: this,
|
|
799
788
|
newValue: newValue,
|
|
@@ -801,14 +790,14 @@ var ObservableValue$$1 = /** @class */ (function (_super) {
|
|
|
801
790
|
});
|
|
802
791
|
}
|
|
803
792
|
};
|
|
804
|
-
ObservableValue
|
|
793
|
+
ObservableValue.prototype.get = function () {
|
|
805
794
|
this.reportObserved();
|
|
806
795
|
return this.dehanceValue(this.value);
|
|
807
796
|
};
|
|
808
|
-
ObservableValue
|
|
809
|
-
return registerInterceptor
|
|
797
|
+
ObservableValue.prototype.intercept = function (handler) {
|
|
798
|
+
return registerInterceptor(this, handler);
|
|
810
799
|
};
|
|
811
|
-
ObservableValue
|
|
800
|
+
ObservableValue.prototype.observe = function (listener, fireImmediately) {
|
|
812
801
|
if (fireImmediately)
|
|
813
802
|
listener({
|
|
814
803
|
object: this,
|
|
@@ -816,21 +805,21 @@ var ObservableValue$$1 = /** @class */ (function (_super) {
|
|
|
816
805
|
newValue: this.value,
|
|
817
806
|
oldValue: undefined
|
|
818
807
|
});
|
|
819
|
-
return registerListener
|
|
808
|
+
return registerListener(this, listener);
|
|
820
809
|
};
|
|
821
|
-
ObservableValue
|
|
810
|
+
ObservableValue.prototype.toJSON = function () {
|
|
822
811
|
return this.get();
|
|
823
812
|
};
|
|
824
|
-
ObservableValue
|
|
813
|
+
ObservableValue.prototype.toString = function () {
|
|
825
814
|
return this.name + "[" + this.value + "]";
|
|
826
815
|
};
|
|
827
|
-
ObservableValue
|
|
828
|
-
return toPrimitive
|
|
816
|
+
ObservableValue.prototype.valueOf = function () {
|
|
817
|
+
return toPrimitive(this.get());
|
|
829
818
|
};
|
|
830
|
-
return ObservableValue
|
|
831
|
-
}(Atom
|
|
832
|
-
ObservableValue
|
|
833
|
-
var isObservableValue
|
|
819
|
+
return ObservableValue;
|
|
820
|
+
}(Atom));
|
|
821
|
+
ObservableValue.prototype[primitiveSymbol()] = ObservableValue.prototype.valueOf;
|
|
822
|
+
var isObservableValue = createInstanceofPredicate("ObservableValue", ObservableValue);
|
|
834
823
|
|
|
835
824
|
/**
|
|
836
825
|
* A node in the state dependency root that observes other nodes, and can be observed itself.
|
|
@@ -851,7 +840,7 @@ var isObservableValue$$1 = createInstanceofPredicate$$1("ObservableValue", Obser
|
|
|
851
840
|
*
|
|
852
841
|
* If at any point it's outside batch and it isn't observed: reset everything and go to 1.
|
|
853
842
|
*/
|
|
854
|
-
var ComputedValue
|
|
843
|
+
var ComputedValue = /** @class */ (function () {
|
|
855
844
|
/**
|
|
856
845
|
* Create a new computed value based on a function expression.
|
|
857
846
|
*
|
|
@@ -864,7 +853,7 @@ var ComputedValue$$1 = /** @class */ (function () {
|
|
|
864
853
|
* don't want to notify observers if it is structurally the same.
|
|
865
854
|
* This is useful for working with vectors, mouse coordinates etc.
|
|
866
855
|
*/
|
|
867
|
-
function ComputedValue
|
|
856
|
+
function ComputedValue(options) {
|
|
868
857
|
this.dependenciesState = exports.IDerivationState.NOT_TRACKING;
|
|
869
858
|
this.observing = []; // nodes we are looking at. Our value depends on these nodes
|
|
870
859
|
this.newObserving = null; // during tracking it's an array with new observed observers
|
|
@@ -877,66 +866,66 @@ var ComputedValue$$1 = /** @class */ (function () {
|
|
|
877
866
|
this.lastAccessedBy = 0;
|
|
878
867
|
this.lowestObserverState = exports.IDerivationState.UP_TO_DATE;
|
|
879
868
|
this.unboundDepsCount = 0;
|
|
880
|
-
this.__mapid = "#" + getNextId
|
|
881
|
-
this.value = new CaughtException
|
|
869
|
+
this.__mapid = "#" + getNextId();
|
|
870
|
+
this.value = new CaughtException(null);
|
|
882
871
|
this.isComputing = false; // to check for cycles
|
|
883
872
|
this.isRunningSetter = false;
|
|
884
|
-
this.isTracing = TraceMode
|
|
873
|
+
this.isTracing = TraceMode.NONE;
|
|
885
874
|
if (process.env.NODE_ENV !== "production" && !options.get)
|
|
886
|
-
return fail
|
|
875
|
+
return fail("missing option for computed: get");
|
|
887
876
|
this.derivation = options.get;
|
|
888
|
-
this.name = options.name || "ComputedValue@" + getNextId
|
|
877
|
+
this.name = options.name || "ComputedValue@" + getNextId();
|
|
889
878
|
if (options.set)
|
|
890
|
-
this.setter = createAction
|
|
879
|
+
this.setter = createAction(this.name + "-setter", options.set);
|
|
891
880
|
this.equals =
|
|
892
881
|
options.equals ||
|
|
893
882
|
(options.compareStructural || options.struct
|
|
894
|
-
? comparer
|
|
895
|
-
: comparer
|
|
883
|
+
? comparer.structural
|
|
884
|
+
: comparer.default);
|
|
896
885
|
this.scope = options.context;
|
|
897
886
|
this.requiresReaction = !!options.requiresReaction;
|
|
898
887
|
this.keepAlive = !!options.keepAlive;
|
|
899
888
|
}
|
|
900
|
-
ComputedValue
|
|
901
|
-
propagateMaybeChanged
|
|
889
|
+
ComputedValue.prototype.onBecomeStale = function () {
|
|
890
|
+
propagateMaybeChanged(this);
|
|
902
891
|
};
|
|
903
|
-
ComputedValue
|
|
904
|
-
ComputedValue
|
|
892
|
+
ComputedValue.prototype.onBecomeUnobserved = function () { };
|
|
893
|
+
ComputedValue.prototype.onBecomeObserved = function () { };
|
|
905
894
|
/**
|
|
906
895
|
* Returns the current value of this computed value.
|
|
907
896
|
* Will evaluate its computation first if needed.
|
|
908
897
|
*/
|
|
909
|
-
ComputedValue
|
|
898
|
+
ComputedValue.prototype.get = function () {
|
|
910
899
|
if (this.isComputing)
|
|
911
|
-
fail
|
|
912
|
-
if (globalState
|
|
913
|
-
if (shouldCompute
|
|
900
|
+
fail("Cycle detected in computation " + this.name + ": " + this.derivation);
|
|
901
|
+
if (globalState.inBatch === 0 && this.observers.length === 0 && !this.keepAlive) {
|
|
902
|
+
if (shouldCompute(this)) {
|
|
914
903
|
this.warnAboutUntrackedRead();
|
|
915
|
-
startBatch
|
|
904
|
+
startBatch(); // See perf test 'computed memoization'
|
|
916
905
|
this.value = this.computeValue(false);
|
|
917
|
-
endBatch
|
|
906
|
+
endBatch();
|
|
918
907
|
}
|
|
919
908
|
}
|
|
920
909
|
else {
|
|
921
|
-
reportObserved
|
|
922
|
-
if (shouldCompute
|
|
910
|
+
reportObserved(this);
|
|
911
|
+
if (shouldCompute(this))
|
|
923
912
|
if (this.trackAndCompute())
|
|
924
|
-
propagateChangeConfirmed
|
|
913
|
+
propagateChangeConfirmed(this);
|
|
925
914
|
}
|
|
926
915
|
var result = this.value;
|
|
927
|
-
if (isCaughtException
|
|
916
|
+
if (isCaughtException(result))
|
|
928
917
|
throw result.cause;
|
|
929
918
|
return result;
|
|
930
919
|
};
|
|
931
|
-
ComputedValue
|
|
920
|
+
ComputedValue.prototype.peek = function () {
|
|
932
921
|
var res = this.computeValue(false);
|
|
933
|
-
if (isCaughtException
|
|
922
|
+
if (isCaughtException(res))
|
|
934
923
|
throw res.cause;
|
|
935
924
|
return res;
|
|
936
925
|
};
|
|
937
|
-
ComputedValue
|
|
926
|
+
ComputedValue.prototype.set = function (value) {
|
|
938
927
|
if (this.setter) {
|
|
939
|
-
invariant
|
|
928
|
+
invariant(!this.isRunningSetter, "The setter of computed value '" + this.name + "' is trying to update itself. Did you intend to update an _observable_ value, instead of the computed property?");
|
|
940
929
|
this.isRunningSetter = true;
|
|
941
930
|
try {
|
|
942
931
|
this.setter.call(this.scope, value);
|
|
@@ -946,12 +935,12 @@ var ComputedValue$$1 = /** @class */ (function () {
|
|
|
946
935
|
}
|
|
947
936
|
}
|
|
948
937
|
else
|
|
949
|
-
invariant
|
|
938
|
+
invariant(false, process.env.NODE_ENV !== "production" &&
|
|
950
939
|
"[ComputedValue '" + this.name + "'] It is not possible to assign a new value to a computed value.");
|
|
951
940
|
};
|
|
952
|
-
ComputedValue
|
|
953
|
-
if (isSpyEnabled
|
|
954
|
-
spyReport
|
|
941
|
+
ComputedValue.prototype.trackAndCompute = function () {
|
|
942
|
+
if (isSpyEnabled()) {
|
|
943
|
+
spyReport({
|
|
955
944
|
object: this.scope,
|
|
956
945
|
type: "compute",
|
|
957
946
|
name: this.name
|
|
@@ -962,23 +951,23 @@ var ComputedValue$$1 = /** @class */ (function () {
|
|
|
962
951
|
/* see #1208 */ this.dependenciesState === exports.IDerivationState.NOT_TRACKING;
|
|
963
952
|
var newValue = this.computeValue(true);
|
|
964
953
|
var changed = wasSuspended ||
|
|
965
|
-
isCaughtException
|
|
966
|
-
isCaughtException
|
|
954
|
+
isCaughtException(oldValue) ||
|
|
955
|
+
isCaughtException(newValue) ||
|
|
967
956
|
!this.equals(oldValue, newValue);
|
|
968
957
|
if (changed) {
|
|
969
958
|
this.value = newValue;
|
|
970
959
|
}
|
|
971
960
|
return changed;
|
|
972
961
|
};
|
|
973
|
-
ComputedValue
|
|
962
|
+
ComputedValue.prototype.computeValue = function (track) {
|
|
974
963
|
this.isComputing = true;
|
|
975
|
-
globalState
|
|
964
|
+
globalState.computationDepth++;
|
|
976
965
|
var res;
|
|
977
966
|
if (track) {
|
|
978
|
-
res = trackDerivedFunction
|
|
967
|
+
res = trackDerivedFunction(this, this.derivation, this.scope);
|
|
979
968
|
}
|
|
980
969
|
else {
|
|
981
|
-
if (globalState
|
|
970
|
+
if (globalState.disableErrorBoundaries === true) {
|
|
982
971
|
res = this.derivation.call(this.scope);
|
|
983
972
|
}
|
|
984
973
|
else {
|
|
@@ -986,101 +975,101 @@ var ComputedValue$$1 = /** @class */ (function () {
|
|
|
986
975
|
res = this.derivation.call(this.scope);
|
|
987
976
|
}
|
|
988
977
|
catch (e) {
|
|
989
|
-
res = new CaughtException
|
|
978
|
+
res = new CaughtException(e);
|
|
990
979
|
}
|
|
991
980
|
}
|
|
992
981
|
}
|
|
993
|
-
globalState
|
|
982
|
+
globalState.computationDepth--;
|
|
994
983
|
this.isComputing = false;
|
|
995
984
|
return res;
|
|
996
985
|
};
|
|
997
|
-
ComputedValue
|
|
986
|
+
ComputedValue.prototype.suspend = function () {
|
|
998
987
|
if (!this.keepAlive) {
|
|
999
|
-
clearObserving
|
|
988
|
+
clearObserving(this);
|
|
1000
989
|
this.value = undefined; // don't hold on to computed value!
|
|
1001
990
|
}
|
|
1002
991
|
};
|
|
1003
|
-
ComputedValue
|
|
992
|
+
ComputedValue.prototype.observe = function (listener, fireImmediately) {
|
|
1004
993
|
var _this = this;
|
|
1005
994
|
var firstTime = true;
|
|
1006
995
|
var prevValue = undefined;
|
|
1007
|
-
return autorun
|
|
996
|
+
return autorun(function () {
|
|
1008
997
|
var newValue = _this.get();
|
|
1009
998
|
if (!firstTime || fireImmediately) {
|
|
1010
|
-
var prevU = untrackedStart
|
|
999
|
+
var prevU = untrackedStart();
|
|
1011
1000
|
listener({
|
|
1012
1001
|
type: "update",
|
|
1013
1002
|
object: _this,
|
|
1014
1003
|
newValue: newValue,
|
|
1015
1004
|
oldValue: prevValue
|
|
1016
1005
|
});
|
|
1017
|
-
untrackedEnd
|
|
1006
|
+
untrackedEnd(prevU);
|
|
1018
1007
|
}
|
|
1019
1008
|
firstTime = false;
|
|
1020
1009
|
prevValue = newValue;
|
|
1021
1010
|
});
|
|
1022
1011
|
};
|
|
1023
|
-
ComputedValue
|
|
1012
|
+
ComputedValue.prototype.warnAboutUntrackedRead = function () {
|
|
1024
1013
|
if (process.env.NODE_ENV === "production")
|
|
1025
1014
|
return;
|
|
1026
1015
|
if (this.requiresReaction === true) {
|
|
1027
|
-
fail
|
|
1016
|
+
fail("[mobx] Computed value " + this.name + " is read outside a reactive context");
|
|
1028
1017
|
}
|
|
1029
|
-
if (this.isTracing !== TraceMode
|
|
1018
|
+
if (this.isTracing !== TraceMode.NONE) {
|
|
1030
1019
|
console.log("[mobx.trace] '" + this.name + "' is being read outside a reactive context. Doing a full recompute");
|
|
1031
1020
|
}
|
|
1032
|
-
if (globalState
|
|
1021
|
+
if (globalState.computedRequiresReaction) {
|
|
1033
1022
|
console.warn("[mobx] Computed value " + this.name + " is being read outside a reactive context. Doing a full recompute");
|
|
1034
1023
|
}
|
|
1035
1024
|
};
|
|
1036
|
-
ComputedValue
|
|
1025
|
+
ComputedValue.prototype.toJSON = function () {
|
|
1037
1026
|
return this.get();
|
|
1038
1027
|
};
|
|
1039
|
-
ComputedValue
|
|
1028
|
+
ComputedValue.prototype.toString = function () {
|
|
1040
1029
|
return this.name + "[" + this.derivation.toString() + "]";
|
|
1041
1030
|
};
|
|
1042
|
-
ComputedValue
|
|
1043
|
-
return toPrimitive
|
|
1031
|
+
ComputedValue.prototype.valueOf = function () {
|
|
1032
|
+
return toPrimitive(this.get());
|
|
1044
1033
|
};
|
|
1045
|
-
return ComputedValue
|
|
1034
|
+
return ComputedValue;
|
|
1046
1035
|
}());
|
|
1047
|
-
ComputedValue
|
|
1048
|
-
var isComputedValue
|
|
1036
|
+
ComputedValue.prototype[primitiveSymbol()] = ComputedValue.prototype.valueOf;
|
|
1037
|
+
var isComputedValue = createInstanceofPredicate("ComputedValue", ComputedValue);
|
|
1049
1038
|
|
|
1050
|
-
(function (IDerivationState
|
|
1039
|
+
(function (IDerivationState) {
|
|
1051
1040
|
// before being run or (outside batch and not being observed)
|
|
1052
1041
|
// at this point derivation is not holding any data about dependency tree
|
|
1053
|
-
IDerivationState
|
|
1042
|
+
IDerivationState[IDerivationState["NOT_TRACKING"] = -1] = "NOT_TRACKING";
|
|
1054
1043
|
// no shallow dependency changed since last computation
|
|
1055
1044
|
// won't recalculate derivation
|
|
1056
1045
|
// this is what makes mobx fast
|
|
1057
|
-
IDerivationState
|
|
1046
|
+
IDerivationState[IDerivationState["UP_TO_DATE"] = 0] = "UP_TO_DATE";
|
|
1058
1047
|
// some deep dependency changed, but don't know if shallow dependency changed
|
|
1059
1048
|
// will require to check first if UP_TO_DATE or POSSIBLY_STALE
|
|
1060
1049
|
// currently only ComputedValue will propagate POSSIBLY_STALE
|
|
1061
1050
|
//
|
|
1062
1051
|
// having this state is second big optimization:
|
|
1063
1052
|
// don't have to recompute on every dependency change, but only when it's needed
|
|
1064
|
-
IDerivationState
|
|
1053
|
+
IDerivationState[IDerivationState["POSSIBLY_STALE"] = 1] = "POSSIBLY_STALE";
|
|
1065
1054
|
// A shallow dependency has changed since last computation and the derivation
|
|
1066
1055
|
// will need to recompute when it's needed next.
|
|
1067
|
-
IDerivationState
|
|
1056
|
+
IDerivationState[IDerivationState["STALE"] = 2] = "STALE";
|
|
1068
1057
|
})(exports.IDerivationState || (exports.IDerivationState = {}));
|
|
1069
|
-
var TraceMode
|
|
1070
|
-
(function (TraceMode
|
|
1071
|
-
TraceMode
|
|
1072
|
-
TraceMode
|
|
1073
|
-
TraceMode
|
|
1074
|
-
})(TraceMode
|
|
1075
|
-
var CaughtException
|
|
1076
|
-
function CaughtException
|
|
1058
|
+
var TraceMode;
|
|
1059
|
+
(function (TraceMode) {
|
|
1060
|
+
TraceMode[TraceMode["NONE"] = 0] = "NONE";
|
|
1061
|
+
TraceMode[TraceMode["LOG"] = 1] = "LOG";
|
|
1062
|
+
TraceMode[TraceMode["BREAK"] = 2] = "BREAK";
|
|
1063
|
+
})(TraceMode || (TraceMode = {}));
|
|
1064
|
+
var CaughtException = /** @class */ (function () {
|
|
1065
|
+
function CaughtException(cause) {
|
|
1077
1066
|
this.cause = cause;
|
|
1078
1067
|
// Empty
|
|
1079
1068
|
}
|
|
1080
|
-
return CaughtException
|
|
1069
|
+
return CaughtException;
|
|
1081
1070
|
}());
|
|
1082
|
-
function isCaughtException
|
|
1083
|
-
return e instanceof CaughtException
|
|
1071
|
+
function isCaughtException(e) {
|
|
1072
|
+
return e instanceof CaughtException;
|
|
1084
1073
|
}
|
|
1085
1074
|
/**
|
|
1086
1075
|
* Finds out whether any dependency of the derivation has actually changed.
|
|
@@ -1093,7 +1082,7 @@ function isCaughtException$$1(e) {
|
|
|
1093
1082
|
* dependencies of the derivation doesn't change then the derivation should run the same way
|
|
1094
1083
|
* up until accessing x-th dependency.
|
|
1095
1084
|
*/
|
|
1096
|
-
function shouldCompute
|
|
1085
|
+
function shouldCompute(derivation) {
|
|
1097
1086
|
switch (derivation.dependenciesState) {
|
|
1098
1087
|
case exports.IDerivationState.UP_TO_DATE:
|
|
1099
1088
|
return false;
|
|
@@ -1101,12 +1090,12 @@ function shouldCompute$$1(derivation) {
|
|
|
1101
1090
|
case exports.IDerivationState.STALE:
|
|
1102
1091
|
return true;
|
|
1103
1092
|
case exports.IDerivationState.POSSIBLY_STALE: {
|
|
1104
|
-
var prevUntracked = untrackedStart
|
|
1093
|
+
var prevUntracked = untrackedStart(); // no need for those computeds to be reported, they will be picked up in trackDerivedFunction.
|
|
1105
1094
|
var obs = derivation.observing, l = obs.length;
|
|
1106
1095
|
for (var i = 0; i < l; i++) {
|
|
1107
1096
|
var obj = obs[i];
|
|
1108
|
-
if (isComputedValue
|
|
1109
|
-
if (globalState
|
|
1097
|
+
if (isComputedValue(obj)) {
|
|
1098
|
+
if (globalState.disableErrorBoundaries) {
|
|
1110
1099
|
obj.get();
|
|
1111
1100
|
}
|
|
1112
1101
|
else {
|
|
@@ -1115,7 +1104,7 @@ function shouldCompute$$1(derivation) {
|
|
|
1115
1104
|
}
|
|
1116
1105
|
catch (e) {
|
|
1117
1106
|
// we are not interested in the value *or* exception at this moment, but if there is one, notify all
|
|
1118
|
-
untrackedEnd
|
|
1107
|
+
untrackedEnd(prevUntracked);
|
|
1119
1108
|
return true;
|
|
1120
1109
|
}
|
|
1121
1110
|
}
|
|
@@ -1123,13 +1112,13 @@ function shouldCompute$$1(derivation) {
|
|
|
1123
1112
|
// and `derivation` is an observer of `obj`
|
|
1124
1113
|
// invariantShouldCompute(derivation)
|
|
1125
1114
|
if (derivation.dependenciesState === exports.IDerivationState.STALE) {
|
|
1126
|
-
untrackedEnd
|
|
1115
|
+
untrackedEnd(prevUntracked);
|
|
1127
1116
|
return true;
|
|
1128
1117
|
}
|
|
1129
1118
|
}
|
|
1130
1119
|
}
|
|
1131
|
-
changeDependenciesStateTo0
|
|
1132
|
-
untrackedEnd
|
|
1120
|
+
changeDependenciesStateTo0(derivation);
|
|
1121
|
+
untrackedEnd(prevUntracked);
|
|
1133
1122
|
return false;
|
|
1134
1123
|
}
|
|
1135
1124
|
}
|
|
@@ -1143,19 +1132,19 @@ function shouldCompute$$1(derivation) {
|
|
|
1143
1132
|
// )
|
|
1144
1133
|
// fail("Illegal dependency state")
|
|
1145
1134
|
// }
|
|
1146
|
-
function isComputingDerivation
|
|
1147
|
-
return globalState
|
|
1135
|
+
function isComputingDerivation() {
|
|
1136
|
+
return globalState.trackingDerivation !== null; // filter out actions inside computations
|
|
1148
1137
|
}
|
|
1149
|
-
function checkIfStateModificationsAreAllowed
|
|
1150
|
-
var hasObservers
|
|
1138
|
+
function checkIfStateModificationsAreAllowed(atom) {
|
|
1139
|
+
var hasObservers = atom.observers.length > 0;
|
|
1151
1140
|
// Should never be possible to change an observed observable from inside computed, see #798
|
|
1152
|
-
if (globalState
|
|
1153
|
-
fail
|
|
1141
|
+
if (globalState.computationDepth > 0 && hasObservers)
|
|
1142
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
1154
1143
|
"Computed values are not allowed to cause side effects by changing observables that are already being observed. Tried to modify: " + atom.name);
|
|
1155
1144
|
// Should not be possible to change observed state outside strict mode, except during initialization, see #563
|
|
1156
|
-
if (!globalState
|
|
1157
|
-
fail
|
|
1158
|
-
(globalState
|
|
1145
|
+
if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "strict"))
|
|
1146
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
1147
|
+
(globalState.enforceActions
|
|
1159
1148
|
? "Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an `action` if this change is intended. Tried to modify: "
|
|
1160
1149
|
: "Side effects like changing state are not allowed at this point. Are you trying to modify state from, for example, the render function of a React component? Tried to modify: ") +
|
|
1161
1150
|
atom.name);
|
|
@@ -1165,17 +1154,17 @@ function checkIfStateModificationsAreAllowed$$1(atom) {
|
|
|
1165
1154
|
* The tracking information is stored on the `derivation` object and the derivation is registered
|
|
1166
1155
|
* as observer of any of the accessed observables.
|
|
1167
1156
|
*/
|
|
1168
|
-
function trackDerivedFunction
|
|
1157
|
+
function trackDerivedFunction(derivation, f, context) {
|
|
1169
1158
|
// pre allocate array allocation + room for variation in deps
|
|
1170
1159
|
// array will be trimmed by bindDependencies
|
|
1171
|
-
changeDependenciesStateTo0
|
|
1160
|
+
changeDependenciesStateTo0(derivation);
|
|
1172
1161
|
derivation.newObserving = new Array(derivation.observing.length + 100);
|
|
1173
1162
|
derivation.unboundDepsCount = 0;
|
|
1174
|
-
derivation.runId = ++globalState
|
|
1175
|
-
var prevTracking = globalState
|
|
1176
|
-
globalState
|
|
1163
|
+
derivation.runId = ++globalState.runId;
|
|
1164
|
+
var prevTracking = globalState.trackingDerivation;
|
|
1165
|
+
globalState.trackingDerivation = derivation;
|
|
1177
1166
|
var result;
|
|
1178
|
-
if (globalState
|
|
1167
|
+
if (globalState.disableErrorBoundaries === true) {
|
|
1179
1168
|
result = f.call(context);
|
|
1180
1169
|
}
|
|
1181
1170
|
else {
|
|
@@ -1183,10 +1172,10 @@ function trackDerivedFunction$$1(derivation, f, context) {
|
|
|
1183
1172
|
result = f.call(context);
|
|
1184
1173
|
}
|
|
1185
1174
|
catch (e) {
|
|
1186
|
-
result = new CaughtException
|
|
1175
|
+
result = new CaughtException(e);
|
|
1187
1176
|
}
|
|
1188
1177
|
}
|
|
1189
|
-
globalState
|
|
1178
|
+
globalState.trackingDerivation = prevTracking;
|
|
1190
1179
|
bindDependencies(derivation);
|
|
1191
1180
|
return result;
|
|
1192
1181
|
}
|
|
@@ -1227,7 +1216,7 @@ function bindDependencies(derivation) {
|
|
|
1227
1216
|
while (l--) {
|
|
1228
1217
|
var dep = prevObserving[l];
|
|
1229
1218
|
if (dep.diffValue === 0) {
|
|
1230
|
-
removeObserver
|
|
1219
|
+
removeObserver(dep, derivation);
|
|
1231
1220
|
}
|
|
1232
1221
|
dep.diffValue = 0;
|
|
1233
1222
|
}
|
|
@@ -1238,7 +1227,7 @@ function bindDependencies(derivation) {
|
|
|
1238
1227
|
var dep = observing[i0];
|
|
1239
1228
|
if (dep.diffValue === 1) {
|
|
1240
1229
|
dep.diffValue = 0;
|
|
1241
|
-
addObserver
|
|
1230
|
+
addObserver(dep, derivation);
|
|
1242
1231
|
}
|
|
1243
1232
|
}
|
|
1244
1233
|
// Some new observed derivations may become stale during this derivation computation
|
|
@@ -1248,34 +1237,34 @@ function bindDependencies(derivation) {
|
|
|
1248
1237
|
derivation.onBecomeStale();
|
|
1249
1238
|
}
|
|
1250
1239
|
}
|
|
1251
|
-
function clearObserving
|
|
1240
|
+
function clearObserving(derivation) {
|
|
1252
1241
|
// invariant(globalState.inBatch > 0, "INTERNAL ERROR clearObserving should be called only inside batch");
|
|
1253
1242
|
var obs = derivation.observing;
|
|
1254
1243
|
derivation.observing = [];
|
|
1255
1244
|
var i = obs.length;
|
|
1256
1245
|
while (i--)
|
|
1257
|
-
removeObserver
|
|
1246
|
+
removeObserver(obs[i], derivation);
|
|
1258
1247
|
derivation.dependenciesState = exports.IDerivationState.NOT_TRACKING;
|
|
1259
1248
|
}
|
|
1260
|
-
function untracked
|
|
1261
|
-
var prev = untrackedStart
|
|
1262
|
-
var res = action
|
|
1263
|
-
untrackedEnd
|
|
1249
|
+
function untracked(action) {
|
|
1250
|
+
var prev = untrackedStart();
|
|
1251
|
+
var res = action();
|
|
1252
|
+
untrackedEnd(prev);
|
|
1264
1253
|
return res;
|
|
1265
1254
|
}
|
|
1266
|
-
function untrackedStart
|
|
1267
|
-
var prev = globalState
|
|
1268
|
-
globalState
|
|
1255
|
+
function untrackedStart() {
|
|
1256
|
+
var prev = globalState.trackingDerivation;
|
|
1257
|
+
globalState.trackingDerivation = null;
|
|
1269
1258
|
return prev;
|
|
1270
1259
|
}
|
|
1271
|
-
function untrackedEnd
|
|
1272
|
-
globalState
|
|
1260
|
+
function untrackedEnd(prev) {
|
|
1261
|
+
globalState.trackingDerivation = prev;
|
|
1273
1262
|
}
|
|
1274
1263
|
/**
|
|
1275
1264
|
* needed to keep `lowestObserverState` correct. when changing from (2 or 1) to 0
|
|
1276
1265
|
*
|
|
1277
1266
|
*/
|
|
1278
|
-
function changeDependenciesStateTo0
|
|
1267
|
+
function changeDependenciesStateTo0(derivation) {
|
|
1279
1268
|
if (derivation.dependenciesState === exports.IDerivationState.UP_TO_DATE)
|
|
1280
1269
|
return;
|
|
1281
1270
|
derivation.dependenciesState = exports.IDerivationState.UP_TO_DATE;
|
|
@@ -1297,8 +1286,8 @@ var persistentKeys = [
|
|
|
1297
1286
|
"runId",
|
|
1298
1287
|
"UNCHANGED"
|
|
1299
1288
|
];
|
|
1300
|
-
var MobXGlobals
|
|
1301
|
-
function MobXGlobals
|
|
1289
|
+
var MobXGlobals = /** @class */ (function () {
|
|
1290
|
+
function MobXGlobals() {
|
|
1302
1291
|
/**
|
|
1303
1292
|
* MobXGlobals version.
|
|
1304
1293
|
* MobX compatiblity with other versions loaded in memory as long as this version matches.
|
|
@@ -1369,6 +1358,11 @@ var MobXGlobals$$1 = /** @class */ (function () {
|
|
|
1369
1358
|
* Warn if computed values are accessed outside a reactive context
|
|
1370
1359
|
*/
|
|
1371
1360
|
this.computedRequiresReaction = false;
|
|
1361
|
+
/**
|
|
1362
|
+
* Allows overwriting of computed properties, useful in tests but not prod as it can cause
|
|
1363
|
+
* memory leaks. See https://github.com/mobxjs/mobx/issues/1867
|
|
1364
|
+
*/
|
|
1365
|
+
this.computedConfigurable = false;
|
|
1372
1366
|
/*
|
|
1373
1367
|
* Don't catch and rethrow exceptions. This is useful for inspecting the state of
|
|
1374
1368
|
* the stack when an exception occurs while debugging.
|
|
@@ -1380,23 +1374,23 @@ var MobXGlobals$$1 = /** @class */ (function () {
|
|
|
1380
1374
|
*/
|
|
1381
1375
|
this.suppressReactionErrors = false;
|
|
1382
1376
|
}
|
|
1383
|
-
return MobXGlobals
|
|
1377
|
+
return MobXGlobals;
|
|
1384
1378
|
}());
|
|
1385
1379
|
var canMergeGlobalState = true;
|
|
1386
1380
|
var isolateCalled = false;
|
|
1387
|
-
var globalState
|
|
1388
|
-
var global = getGlobal
|
|
1381
|
+
var globalState = (function () {
|
|
1382
|
+
var global = getGlobal();
|
|
1389
1383
|
if (global.__mobxInstanceCount > 0 && !global.__mobxGlobals)
|
|
1390
1384
|
canMergeGlobalState = false;
|
|
1391
|
-
if (global.__mobxGlobals && global.__mobxGlobals.version !== new MobXGlobals
|
|
1385
|
+
if (global.__mobxGlobals && global.__mobxGlobals.version !== new MobXGlobals().version)
|
|
1392
1386
|
canMergeGlobalState = false;
|
|
1393
1387
|
if (!canMergeGlobalState) {
|
|
1394
1388
|
setTimeout(function () {
|
|
1395
1389
|
if (!isolateCalled) {
|
|
1396
|
-
fail
|
|
1390
|
+
fail("There are multiple, different versions of MobX active. Make sure MobX is loaded only once or use `configure({ isolateGlobalState: true })`");
|
|
1397
1391
|
}
|
|
1398
1392
|
}, 1);
|
|
1399
|
-
return new MobXGlobals
|
|
1393
|
+
return new MobXGlobals();
|
|
1400
1394
|
}
|
|
1401
1395
|
else if (global.__mobxGlobals) {
|
|
1402
1396
|
global.__mobxInstanceCount += 1;
|
|
@@ -1406,41 +1400,41 @@ var globalState$$1 = (function () {
|
|
|
1406
1400
|
}
|
|
1407
1401
|
else {
|
|
1408
1402
|
global.__mobxInstanceCount = 1;
|
|
1409
|
-
return (global.__mobxGlobals = new MobXGlobals
|
|
1403
|
+
return (global.__mobxGlobals = new MobXGlobals());
|
|
1410
1404
|
}
|
|
1411
1405
|
})();
|
|
1412
|
-
function isolateGlobalState
|
|
1413
|
-
if (globalState
|
|
1414
|
-
globalState
|
|
1415
|
-
globalState
|
|
1416
|
-
fail
|
|
1406
|
+
function isolateGlobalState() {
|
|
1407
|
+
if (globalState.pendingReactions.length ||
|
|
1408
|
+
globalState.inBatch ||
|
|
1409
|
+
globalState.isRunningReactions)
|
|
1410
|
+
fail("isolateGlobalState should be called before MobX is running any reactions");
|
|
1417
1411
|
isolateCalled = true;
|
|
1418
1412
|
if (canMergeGlobalState) {
|
|
1419
|
-
if (--getGlobal
|
|
1420
|
-
getGlobal
|
|
1421
|
-
globalState
|
|
1413
|
+
if (--getGlobal().__mobxInstanceCount === 0)
|
|
1414
|
+
getGlobal().__mobxGlobals = undefined;
|
|
1415
|
+
globalState = new MobXGlobals();
|
|
1422
1416
|
}
|
|
1423
1417
|
}
|
|
1424
|
-
function getGlobalState
|
|
1425
|
-
return globalState
|
|
1418
|
+
function getGlobalState() {
|
|
1419
|
+
return globalState;
|
|
1426
1420
|
}
|
|
1427
1421
|
/**
|
|
1428
1422
|
* For testing purposes only; this will break the internal state of existing observables,
|
|
1429
1423
|
* but can be used to get back at a stable state after throwing errors
|
|
1430
1424
|
*/
|
|
1431
|
-
function resetGlobalState
|
|
1432
|
-
var defaultGlobals = new MobXGlobals
|
|
1425
|
+
function resetGlobalState() {
|
|
1426
|
+
var defaultGlobals = new MobXGlobals();
|
|
1433
1427
|
for (var key in defaultGlobals)
|
|
1434
1428
|
if (persistentKeys.indexOf(key) === -1)
|
|
1435
|
-
globalState
|
|
1436
|
-
globalState
|
|
1429
|
+
globalState[key] = defaultGlobals[key];
|
|
1430
|
+
globalState.allowStateChanges = !globalState.enforceActions;
|
|
1437
1431
|
}
|
|
1438
1432
|
|
|
1439
|
-
function hasObservers
|
|
1440
|
-
return observable
|
|
1433
|
+
function hasObservers(observable) {
|
|
1434
|
+
return observable.observers && observable.observers.length > 0;
|
|
1441
1435
|
}
|
|
1442
|
-
function getObservers
|
|
1443
|
-
return observable
|
|
1436
|
+
function getObservers(observable) {
|
|
1437
|
+
return observable.observers;
|
|
1444
1438
|
}
|
|
1445
1439
|
// function invariantObservers(observable: IObservable) {
|
|
1446
1440
|
// const list = observable.observers
|
|
@@ -1459,34 +1453,34 @@ function getObservers$$1(observable$$1) {
|
|
|
1459
1453
|
// "INTERNAL ERROR there is no junk in map"
|
|
1460
1454
|
// )
|
|
1461
1455
|
// }
|
|
1462
|
-
function addObserver
|
|
1456
|
+
function addObserver(observable, node) {
|
|
1463
1457
|
// invariant(node.dependenciesState !== -1, "INTERNAL ERROR, can add only dependenciesState !== -1");
|
|
1464
1458
|
// invariant(observable._observers.indexOf(node) === -1, "INTERNAL ERROR add already added node");
|
|
1465
1459
|
// invariantObservers(observable);
|
|
1466
|
-
var l = observable
|
|
1460
|
+
var l = observable.observers.length;
|
|
1467
1461
|
if (l) {
|
|
1468
1462
|
// because object assignment is relatively expensive, let's not store data about index 0.
|
|
1469
|
-
observable
|
|
1463
|
+
observable.observersIndexes[node.__mapid] = l;
|
|
1470
1464
|
}
|
|
1471
|
-
observable
|
|
1472
|
-
if (observable
|
|
1473
|
-
observable
|
|
1465
|
+
observable.observers[l] = node;
|
|
1466
|
+
if (observable.lowestObserverState > node.dependenciesState)
|
|
1467
|
+
observable.lowestObserverState = node.dependenciesState;
|
|
1474
1468
|
// invariantObservers(observable);
|
|
1475
1469
|
// invariant(observable._observers.indexOf(node) !== -1, "INTERNAL ERROR didn't add node");
|
|
1476
1470
|
}
|
|
1477
|
-
function removeObserver
|
|
1471
|
+
function removeObserver(observable, node) {
|
|
1478
1472
|
// invariant(globalState.inBatch > 0, "INTERNAL ERROR, remove should be called only inside batch");
|
|
1479
1473
|
// invariant(observable._observers.indexOf(node) !== -1, "INTERNAL ERROR remove already removed node");
|
|
1480
1474
|
// invariantObservers(observable);
|
|
1481
|
-
if (observable
|
|
1475
|
+
if (observable.observers.length === 1) {
|
|
1482
1476
|
// deleting last observer
|
|
1483
|
-
observable
|
|
1484
|
-
queueForUnobservation
|
|
1477
|
+
observable.observers.length = 0;
|
|
1478
|
+
queueForUnobservation(observable);
|
|
1485
1479
|
}
|
|
1486
1480
|
else {
|
|
1487
1481
|
// deleting from _observersIndexes is straight forward, to delete from _observers, let's swap `node` with last element
|
|
1488
|
-
var list = observable
|
|
1489
|
-
var map = observable
|
|
1482
|
+
var list = observable.observers;
|
|
1483
|
+
var map = observable.observersIndexes;
|
|
1490
1484
|
var filler = list.pop(); // get last element, which should fill the place of `node`, so the array doesn't have holes
|
|
1491
1485
|
if (filler !== node) {
|
|
1492
1486
|
// otherwise node was the last element, which already got removed from array
|
|
@@ -1505,11 +1499,11 @@ function removeObserver$$1(observable$$1, node) {
|
|
|
1505
1499
|
// invariantObservers(observable);
|
|
1506
1500
|
// invariant(observable._observers.indexOf(node) === -1, "INTERNAL ERROR remove already removed node2");
|
|
1507
1501
|
}
|
|
1508
|
-
function queueForUnobservation
|
|
1509
|
-
if (observable
|
|
1502
|
+
function queueForUnobservation(observable) {
|
|
1503
|
+
if (observable.isPendingUnobservation === false) {
|
|
1510
1504
|
// invariant(observable._observers.length === 0, "INTERNAL ERROR, should only queue for unobservation unobserved observables");
|
|
1511
|
-
observable
|
|
1512
|
-
globalState
|
|
1505
|
+
observable.isPendingUnobservation = true;
|
|
1506
|
+
globalState.pendingUnobservations.push(observable);
|
|
1513
1507
|
}
|
|
1514
1508
|
}
|
|
1515
1509
|
/**
|
|
@@ -1517,53 +1511,53 @@ function queueForUnobservation$$1(observable$$1) {
|
|
|
1517
1511
|
* During a batch `onBecomeUnobserved` will be called at most once per observable.
|
|
1518
1512
|
* Avoids unnecessary recalculations.
|
|
1519
1513
|
*/
|
|
1520
|
-
function startBatch
|
|
1521
|
-
globalState
|
|
1514
|
+
function startBatch() {
|
|
1515
|
+
globalState.inBatch++;
|
|
1522
1516
|
}
|
|
1523
|
-
function endBatch
|
|
1524
|
-
if (--globalState
|
|
1525
|
-
runReactions
|
|
1517
|
+
function endBatch() {
|
|
1518
|
+
if (--globalState.inBatch === 0) {
|
|
1519
|
+
runReactions();
|
|
1526
1520
|
// the batch is actually about to finish, all unobserving should happen here.
|
|
1527
|
-
var list = globalState
|
|
1521
|
+
var list = globalState.pendingUnobservations;
|
|
1528
1522
|
for (var i = 0; i < list.length; i++) {
|
|
1529
|
-
var observable
|
|
1530
|
-
observable
|
|
1531
|
-
if (observable
|
|
1532
|
-
if (observable
|
|
1523
|
+
var observable = list[i];
|
|
1524
|
+
observable.isPendingUnobservation = false;
|
|
1525
|
+
if (observable.observers.length === 0) {
|
|
1526
|
+
if (observable.isBeingObserved) {
|
|
1533
1527
|
// if this observable had reactive observers, trigger the hooks
|
|
1534
|
-
observable
|
|
1535
|
-
observable
|
|
1528
|
+
observable.isBeingObserved = false;
|
|
1529
|
+
observable.onBecomeUnobserved();
|
|
1536
1530
|
}
|
|
1537
|
-
if (observable
|
|
1531
|
+
if (observable instanceof ComputedValue) {
|
|
1538
1532
|
// computed values are automatically teared down when the last observer leaves
|
|
1539
1533
|
// this process happens recursively, this computed might be the last observabe of another, etc..
|
|
1540
|
-
observable
|
|
1534
|
+
observable.suspend();
|
|
1541
1535
|
}
|
|
1542
1536
|
}
|
|
1543
1537
|
}
|
|
1544
|
-
globalState
|
|
1538
|
+
globalState.pendingUnobservations = [];
|
|
1545
1539
|
}
|
|
1546
1540
|
}
|
|
1547
|
-
function reportObserved
|
|
1548
|
-
var derivation = globalState
|
|
1541
|
+
function reportObserved(observable) {
|
|
1542
|
+
var derivation = globalState.trackingDerivation;
|
|
1549
1543
|
if (derivation !== null) {
|
|
1550
1544
|
/**
|
|
1551
1545
|
* Simple optimization, give each derivation run an unique id (runId)
|
|
1552
1546
|
* Check if last time this observable was accessed the same runId is used
|
|
1553
1547
|
* if this is the case, the relation is already known
|
|
1554
1548
|
*/
|
|
1555
|
-
if (derivation.runId !== observable
|
|
1556
|
-
observable
|
|
1557
|
-
derivation.newObserving[derivation.unboundDepsCount++] = observable
|
|
1558
|
-
if (!observable
|
|
1559
|
-
observable
|
|
1560
|
-
observable
|
|
1549
|
+
if (derivation.runId !== observable.lastAccessedBy) {
|
|
1550
|
+
observable.lastAccessedBy = derivation.runId;
|
|
1551
|
+
derivation.newObserving[derivation.unboundDepsCount++] = observable;
|
|
1552
|
+
if (!observable.isBeingObserved) {
|
|
1553
|
+
observable.isBeingObserved = true;
|
|
1554
|
+
observable.onBecomeObserved();
|
|
1561
1555
|
}
|
|
1562
1556
|
}
|
|
1563
1557
|
return true;
|
|
1564
1558
|
}
|
|
1565
|
-
else if (observable
|
|
1566
|
-
queueForUnobservation
|
|
1559
|
+
else if (observable.observers.length === 0 && globalState.inBatch > 0) {
|
|
1560
|
+
queueForUnobservation(observable);
|
|
1567
1561
|
}
|
|
1568
1562
|
return false;
|
|
1569
1563
|
}
|
|
@@ -1588,18 +1582,18 @@ function reportObserved$$1(observable$$1) {
|
|
|
1588
1582
|
* Also most basic use cases should be ok
|
|
1589
1583
|
*/
|
|
1590
1584
|
// Called by Atom when its value changes
|
|
1591
|
-
function propagateChanged
|
|
1585
|
+
function propagateChanged(observable) {
|
|
1592
1586
|
// invariantLOS(observable, "changed start");
|
|
1593
|
-
if (observable
|
|
1587
|
+
if (observable.lowestObserverState === exports.IDerivationState.STALE)
|
|
1594
1588
|
return;
|
|
1595
|
-
observable
|
|
1596
|
-
var observers = observable
|
|
1589
|
+
observable.lowestObserverState = exports.IDerivationState.STALE;
|
|
1590
|
+
var observers = observable.observers;
|
|
1597
1591
|
var i = observers.length;
|
|
1598
1592
|
while (i--) {
|
|
1599
1593
|
var d = observers[i];
|
|
1600
1594
|
if (d.dependenciesState === exports.IDerivationState.UP_TO_DATE) {
|
|
1601
|
-
if (d.isTracing !== TraceMode
|
|
1602
|
-
logTraceInfo(d, observable
|
|
1595
|
+
if (d.isTracing !== TraceMode.NONE) {
|
|
1596
|
+
logTraceInfo(d, observable);
|
|
1603
1597
|
}
|
|
1604
1598
|
d.onBecomeStale();
|
|
1605
1599
|
}
|
|
@@ -1608,12 +1602,12 @@ function propagateChanged$$1(observable$$1) {
|
|
|
1608
1602
|
// invariantLOS(observable, "changed end");
|
|
1609
1603
|
}
|
|
1610
1604
|
// Called by ComputedValue when it recalculate and its value changed
|
|
1611
|
-
function propagateChangeConfirmed
|
|
1605
|
+
function propagateChangeConfirmed(observable) {
|
|
1612
1606
|
// invariantLOS(observable, "confirmed start");
|
|
1613
|
-
if (observable
|
|
1607
|
+
if (observable.lowestObserverState === exports.IDerivationState.STALE)
|
|
1614
1608
|
return;
|
|
1615
|
-
observable
|
|
1616
|
-
var observers = observable
|
|
1609
|
+
observable.lowestObserverState = exports.IDerivationState.STALE;
|
|
1610
|
+
var observers = observable.observers;
|
|
1617
1611
|
var i = observers.length;
|
|
1618
1612
|
while (i--) {
|
|
1619
1613
|
var d = observers[i];
|
|
@@ -1621,37 +1615,37 @@ function propagateChangeConfirmed$$1(observable$$1) {
|
|
|
1621
1615
|
d.dependenciesState = exports.IDerivationState.STALE;
|
|
1622
1616
|
else if (d.dependenciesState === exports.IDerivationState.UP_TO_DATE // this happens during computing of `d`, just keep lowestObserverState up to date.
|
|
1623
1617
|
)
|
|
1624
|
-
observable
|
|
1618
|
+
observable.lowestObserverState = exports.IDerivationState.UP_TO_DATE;
|
|
1625
1619
|
}
|
|
1626
1620
|
// invariantLOS(observable, "confirmed end");
|
|
1627
1621
|
}
|
|
1628
1622
|
// Used by computed when its dependency changed, but we don't wan't to immediately recompute.
|
|
1629
|
-
function propagateMaybeChanged
|
|
1623
|
+
function propagateMaybeChanged(observable) {
|
|
1630
1624
|
// invariantLOS(observable, "maybe start");
|
|
1631
|
-
if (observable
|
|
1625
|
+
if (observable.lowestObserverState !== exports.IDerivationState.UP_TO_DATE)
|
|
1632
1626
|
return;
|
|
1633
|
-
observable
|
|
1634
|
-
var observers = observable
|
|
1627
|
+
observable.lowestObserverState = exports.IDerivationState.POSSIBLY_STALE;
|
|
1628
|
+
var observers = observable.observers;
|
|
1635
1629
|
var i = observers.length;
|
|
1636
1630
|
while (i--) {
|
|
1637
1631
|
var d = observers[i];
|
|
1638
1632
|
if (d.dependenciesState === exports.IDerivationState.UP_TO_DATE) {
|
|
1639
1633
|
d.dependenciesState = exports.IDerivationState.POSSIBLY_STALE;
|
|
1640
|
-
if (d.isTracing !== TraceMode
|
|
1641
|
-
logTraceInfo(d, observable
|
|
1634
|
+
if (d.isTracing !== TraceMode.NONE) {
|
|
1635
|
+
logTraceInfo(d, observable);
|
|
1642
1636
|
}
|
|
1643
1637
|
d.onBecomeStale();
|
|
1644
1638
|
}
|
|
1645
1639
|
}
|
|
1646
1640
|
// invariantLOS(observable, "maybe end");
|
|
1647
1641
|
}
|
|
1648
|
-
function logTraceInfo(derivation, observable
|
|
1649
|
-
console.log("[mobx.trace] '" + derivation.name + "' is invalidated due to a change in: '" + observable
|
|
1650
|
-
if (derivation.isTracing === TraceMode
|
|
1642
|
+
function logTraceInfo(derivation, observable) {
|
|
1643
|
+
console.log("[mobx.trace] '" + derivation.name + "' is invalidated due to a change in: '" + observable.name + "'");
|
|
1644
|
+
if (derivation.isTracing === TraceMode.BREAK) {
|
|
1651
1645
|
var lines = [];
|
|
1652
|
-
printDepTree(getDependencyTree
|
|
1646
|
+
printDepTree(getDependencyTree(derivation), lines, 1);
|
|
1653
1647
|
// prettier-ignore
|
|
1654
|
-
new Function("debugger;\n/*\nTracing '" + derivation.name + "'\n\nYou are entering this break point because derivation '" + derivation.name + "' is being traced and '" + observable
|
|
1648
|
+
new Function("debugger;\n/*\nTracing '" + derivation.name + "'\n\nYou are entering this break point because derivation '" + derivation.name + "' is being traced and '" + observable.name + "' is now forcing it to update.\nJust follow the stacktrace you should now see in the devtools to see precisely what piece of your code is causing this update\nThe stackframe you are looking for is at least ~6-8 stack-frames up.\n\n" + (derivation instanceof ComputedValue ? derivation.derivation.toString().replace(/[*]\//g, "/") : "") + "\n\nThe dependencies for this derivation are:\n\n" + lines.join("\n") + "\n*/\n ")();
|
|
1655
1649
|
}
|
|
1656
1650
|
}
|
|
1657
1651
|
function printDepTree(tree, lines, depth) {
|
|
@@ -1664,9 +1658,9 @@ function printDepTree(tree, lines, depth) {
|
|
|
1664
1658
|
tree.dependencies.forEach(function (child) { return printDepTree(child, lines, depth + 1); });
|
|
1665
1659
|
}
|
|
1666
1660
|
|
|
1667
|
-
var Reaction
|
|
1668
|
-
function Reaction
|
|
1669
|
-
if (name === void 0) { name = "Reaction@" + getNextId
|
|
1661
|
+
var Reaction = /** @class */ (function () {
|
|
1662
|
+
function Reaction(name, onInvalidate, errorHandler) {
|
|
1663
|
+
if (name === void 0) { name = "Reaction@" + getNextId(); }
|
|
1670
1664
|
this.name = name;
|
|
1671
1665
|
this.onInvalidate = onInvalidate;
|
|
1672
1666
|
this.errorHandler = errorHandler;
|
|
@@ -1676,40 +1670,40 @@ var Reaction$$1 = /** @class */ (function () {
|
|
|
1676
1670
|
this.diffValue = 0;
|
|
1677
1671
|
this.runId = 0;
|
|
1678
1672
|
this.unboundDepsCount = 0;
|
|
1679
|
-
this.__mapid = "#" + getNextId
|
|
1673
|
+
this.__mapid = "#" + getNextId();
|
|
1680
1674
|
this.isDisposed = false;
|
|
1681
1675
|
this._isScheduled = false;
|
|
1682
1676
|
this._isTrackPending = false;
|
|
1683
1677
|
this._isRunning = false;
|
|
1684
|
-
this.isTracing = TraceMode
|
|
1678
|
+
this.isTracing = TraceMode.NONE;
|
|
1685
1679
|
}
|
|
1686
|
-
Reaction
|
|
1680
|
+
Reaction.prototype.onBecomeStale = function () {
|
|
1687
1681
|
this.schedule();
|
|
1688
1682
|
};
|
|
1689
|
-
Reaction
|
|
1683
|
+
Reaction.prototype.schedule = function () {
|
|
1690
1684
|
if (!this._isScheduled) {
|
|
1691
1685
|
this._isScheduled = true;
|
|
1692
|
-
globalState
|
|
1693
|
-
runReactions
|
|
1686
|
+
globalState.pendingReactions.push(this);
|
|
1687
|
+
runReactions();
|
|
1694
1688
|
}
|
|
1695
1689
|
};
|
|
1696
|
-
Reaction
|
|
1690
|
+
Reaction.prototype.isScheduled = function () {
|
|
1697
1691
|
return this._isScheduled;
|
|
1698
1692
|
};
|
|
1699
1693
|
/**
|
|
1700
1694
|
* internal, use schedule() if you intend to kick off a reaction
|
|
1701
1695
|
*/
|
|
1702
|
-
Reaction
|
|
1696
|
+
Reaction.prototype.runReaction = function () {
|
|
1703
1697
|
if (!this.isDisposed) {
|
|
1704
|
-
startBatch
|
|
1698
|
+
startBatch();
|
|
1705
1699
|
this._isScheduled = false;
|
|
1706
|
-
if (shouldCompute
|
|
1700
|
+
if (shouldCompute(this)) {
|
|
1707
1701
|
this._isTrackPending = true;
|
|
1708
1702
|
try {
|
|
1709
1703
|
this.onInvalidate();
|
|
1710
|
-
if (this._isTrackPending && isSpyEnabled
|
|
1704
|
+
if (this._isTrackPending && isSpyEnabled()) {
|
|
1711
1705
|
// onInvalidate didn't trigger track right away..
|
|
1712
|
-
spyReport
|
|
1706
|
+
spyReport({
|
|
1713
1707
|
name: this.name,
|
|
1714
1708
|
type: "scheduled-reaction"
|
|
1715
1709
|
});
|
|
@@ -1719,94 +1713,94 @@ var Reaction$$1 = /** @class */ (function () {
|
|
|
1719
1713
|
this.reportExceptionInDerivation(e);
|
|
1720
1714
|
}
|
|
1721
1715
|
}
|
|
1722
|
-
endBatch
|
|
1716
|
+
endBatch();
|
|
1723
1717
|
}
|
|
1724
1718
|
};
|
|
1725
|
-
Reaction
|
|
1726
|
-
startBatch
|
|
1727
|
-
var notify = isSpyEnabled
|
|
1719
|
+
Reaction.prototype.track = function (fn) {
|
|
1720
|
+
startBatch();
|
|
1721
|
+
var notify = isSpyEnabled();
|
|
1728
1722
|
var startTime;
|
|
1729
1723
|
if (notify) {
|
|
1730
1724
|
startTime = Date.now();
|
|
1731
|
-
spyReportStart
|
|
1725
|
+
spyReportStart({
|
|
1732
1726
|
name: this.name,
|
|
1733
1727
|
type: "reaction"
|
|
1734
1728
|
});
|
|
1735
1729
|
}
|
|
1736
1730
|
this._isRunning = true;
|
|
1737
|
-
var result = trackDerivedFunction
|
|
1731
|
+
var result = trackDerivedFunction(this, fn, undefined);
|
|
1738
1732
|
this._isRunning = false;
|
|
1739
1733
|
this._isTrackPending = false;
|
|
1740
1734
|
if (this.isDisposed) {
|
|
1741
1735
|
// disposed during last run. Clean up everything that was bound after the dispose call.
|
|
1742
|
-
clearObserving
|
|
1736
|
+
clearObserving(this);
|
|
1743
1737
|
}
|
|
1744
|
-
if (isCaughtException
|
|
1738
|
+
if (isCaughtException(result))
|
|
1745
1739
|
this.reportExceptionInDerivation(result.cause);
|
|
1746
1740
|
if (notify) {
|
|
1747
|
-
spyReportEnd
|
|
1741
|
+
spyReportEnd({
|
|
1748
1742
|
time: Date.now() - startTime
|
|
1749
1743
|
});
|
|
1750
1744
|
}
|
|
1751
|
-
endBatch
|
|
1745
|
+
endBatch();
|
|
1752
1746
|
};
|
|
1753
|
-
Reaction
|
|
1747
|
+
Reaction.prototype.reportExceptionInDerivation = function (error) {
|
|
1754
1748
|
var _this = this;
|
|
1755
1749
|
if (this.errorHandler) {
|
|
1756
1750
|
this.errorHandler(error, this);
|
|
1757
1751
|
return;
|
|
1758
1752
|
}
|
|
1759
|
-
if (globalState
|
|
1753
|
+
if (globalState.disableErrorBoundaries)
|
|
1760
1754
|
throw error;
|
|
1761
1755
|
var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this + "'";
|
|
1762
|
-
if (globalState
|
|
1756
|
+
if (globalState.suppressReactionErrors) {
|
|
1763
1757
|
console.warn("[mobx] (error in reaction '" + this.name + "' suppressed, fix error of causing action below)"); // prettier-ignore
|
|
1764
1758
|
}
|
|
1765
1759
|
else {
|
|
1766
1760
|
console.error(message, error);
|
|
1767
1761
|
/** If debugging brought you here, please, read the above message :-). Tnx! */
|
|
1768
1762
|
}
|
|
1769
|
-
if (isSpyEnabled
|
|
1770
|
-
spyReport
|
|
1763
|
+
if (isSpyEnabled()) {
|
|
1764
|
+
spyReport({
|
|
1771
1765
|
type: "error",
|
|
1772
1766
|
name: this.name,
|
|
1773
1767
|
message: message,
|
|
1774
1768
|
error: "" + error
|
|
1775
1769
|
});
|
|
1776
1770
|
}
|
|
1777
|
-
globalState
|
|
1771
|
+
globalState.globalReactionErrorHandlers.forEach(function (f) { return f(error, _this); });
|
|
1778
1772
|
};
|
|
1779
|
-
Reaction
|
|
1773
|
+
Reaction.prototype.dispose = function () {
|
|
1780
1774
|
if (!this.isDisposed) {
|
|
1781
1775
|
this.isDisposed = true;
|
|
1782
1776
|
if (!this._isRunning) {
|
|
1783
1777
|
// if disposed while running, clean up later. Maybe not optimal, but rare case
|
|
1784
|
-
startBatch
|
|
1785
|
-
clearObserving
|
|
1786
|
-
endBatch
|
|
1778
|
+
startBatch();
|
|
1779
|
+
clearObserving(this);
|
|
1780
|
+
endBatch();
|
|
1787
1781
|
}
|
|
1788
1782
|
}
|
|
1789
1783
|
};
|
|
1790
|
-
Reaction
|
|
1784
|
+
Reaction.prototype.getDisposer = function () {
|
|
1791
1785
|
var r = this.dispose.bind(this);
|
|
1792
1786
|
r.$mobx = this;
|
|
1793
1787
|
return r;
|
|
1794
1788
|
};
|
|
1795
|
-
Reaction
|
|
1789
|
+
Reaction.prototype.toString = function () {
|
|
1796
1790
|
return "Reaction[" + this.name + "]";
|
|
1797
1791
|
};
|
|
1798
|
-
Reaction
|
|
1792
|
+
Reaction.prototype.trace = function (enterBreakPoint) {
|
|
1799
1793
|
if (enterBreakPoint === void 0) { enterBreakPoint = false; }
|
|
1800
|
-
trace
|
|
1794
|
+
trace(this, enterBreakPoint);
|
|
1801
1795
|
};
|
|
1802
|
-
return Reaction
|
|
1796
|
+
return Reaction;
|
|
1803
1797
|
}());
|
|
1804
|
-
function onReactionError
|
|
1805
|
-
globalState
|
|
1798
|
+
function onReactionError(handler) {
|
|
1799
|
+
globalState.globalReactionErrorHandlers.push(handler);
|
|
1806
1800
|
return function () {
|
|
1807
|
-
var idx = globalState
|
|
1801
|
+
var idx = globalState.globalReactionErrorHandlers.indexOf(handler);
|
|
1808
1802
|
if (idx >= 0)
|
|
1809
|
-
globalState
|
|
1803
|
+
globalState.globalReactionErrorHandlers.splice(idx, 1);
|
|
1810
1804
|
};
|
|
1811
1805
|
}
|
|
1812
1806
|
/**
|
|
@@ -1816,15 +1810,15 @@ function onReactionError$$1(handler) {
|
|
|
1816
1810
|
*/
|
|
1817
1811
|
var MAX_REACTION_ITERATIONS = 100;
|
|
1818
1812
|
var reactionScheduler = function (f) { return f(); };
|
|
1819
|
-
function runReactions
|
|
1813
|
+
function runReactions() {
|
|
1820
1814
|
// Trampolining, if runReactions are already running, new reactions will be picked up
|
|
1821
|
-
if (globalState
|
|
1815
|
+
if (globalState.inBatch > 0 || globalState.isRunningReactions)
|
|
1822
1816
|
return;
|
|
1823
1817
|
reactionScheduler(runReactionsHelper);
|
|
1824
1818
|
}
|
|
1825
1819
|
function runReactionsHelper() {
|
|
1826
|
-
globalState
|
|
1827
|
-
var allReactions = globalState
|
|
1820
|
+
globalState.isRunningReactions = true;
|
|
1821
|
+
var allReactions = globalState.pendingReactions;
|
|
1828
1822
|
var iterations = 0;
|
|
1829
1823
|
// While running reactions, new reactions might be triggered.
|
|
1830
1824
|
// Hence we work with two variables and check whether
|
|
@@ -1839,57 +1833,57 @@ function runReactionsHelper() {
|
|
|
1839
1833
|
for (var i = 0, l = remainingReactions.length; i < l; i++)
|
|
1840
1834
|
remainingReactions[i].runReaction();
|
|
1841
1835
|
}
|
|
1842
|
-
globalState
|
|
1836
|
+
globalState.isRunningReactions = false;
|
|
1843
1837
|
}
|
|
1844
|
-
var isReaction
|
|
1845
|
-
function setReactionScheduler
|
|
1838
|
+
var isReaction = createInstanceofPredicate("Reaction", Reaction);
|
|
1839
|
+
function setReactionScheduler(fn) {
|
|
1846
1840
|
var baseScheduler = reactionScheduler;
|
|
1847
1841
|
reactionScheduler = function (f) { return fn(function () { return baseScheduler(f); }); };
|
|
1848
1842
|
}
|
|
1849
1843
|
|
|
1850
|
-
function isSpyEnabled
|
|
1851
|
-
return !!globalState
|
|
1844
|
+
function isSpyEnabled() {
|
|
1845
|
+
return !!globalState.spyListeners.length;
|
|
1852
1846
|
}
|
|
1853
|
-
function spyReport
|
|
1854
|
-
if (!globalState
|
|
1847
|
+
function spyReport(event) {
|
|
1848
|
+
if (!globalState.spyListeners.length)
|
|
1855
1849
|
return;
|
|
1856
|
-
var listeners = globalState
|
|
1850
|
+
var listeners = globalState.spyListeners;
|
|
1857
1851
|
for (var i = 0, l = listeners.length; i < l; i++)
|
|
1858
1852
|
listeners[i](event);
|
|
1859
1853
|
}
|
|
1860
|
-
function spyReportStart
|
|
1854
|
+
function spyReportStart(event) {
|
|
1861
1855
|
var change = __assign({}, event, { spyReportStart: true });
|
|
1862
|
-
spyReport
|
|
1856
|
+
spyReport(change);
|
|
1863
1857
|
}
|
|
1864
1858
|
var END_EVENT = { spyReportEnd: true };
|
|
1865
|
-
function spyReportEnd
|
|
1859
|
+
function spyReportEnd(change) {
|
|
1866
1860
|
if (change)
|
|
1867
|
-
spyReport
|
|
1861
|
+
spyReport(__assign({}, change, { spyReportEnd: true }));
|
|
1868
1862
|
else
|
|
1869
|
-
spyReport
|
|
1863
|
+
spyReport(END_EVENT);
|
|
1870
1864
|
}
|
|
1871
|
-
function spy
|
|
1872
|
-
globalState
|
|
1873
|
-
return once
|
|
1874
|
-
globalState
|
|
1865
|
+
function spy(listener) {
|
|
1866
|
+
globalState.spyListeners.push(listener);
|
|
1867
|
+
return once(function () {
|
|
1868
|
+
globalState.spyListeners = globalState.spyListeners.filter(function (l) { return l !== listener; });
|
|
1875
1869
|
});
|
|
1876
1870
|
}
|
|
1877
1871
|
|
|
1878
1872
|
function dontReassignFields() {
|
|
1879
|
-
fail
|
|
1873
|
+
fail(process.env.NODE_ENV !== "production" && "@action fields are not reassignable");
|
|
1880
1874
|
}
|
|
1881
|
-
function namedActionDecorator
|
|
1875
|
+
function namedActionDecorator(name) {
|
|
1882
1876
|
return function (target, prop, descriptor) {
|
|
1883
1877
|
if (descriptor) {
|
|
1884
1878
|
if (process.env.NODE_ENV !== "production" && descriptor.get !== undefined) {
|
|
1885
|
-
return fail
|
|
1879
|
+
return fail("@action cannot be used with getters");
|
|
1886
1880
|
}
|
|
1887
1881
|
// babel / typescript
|
|
1888
1882
|
// @action method() { }
|
|
1889
1883
|
if (descriptor.value) {
|
|
1890
1884
|
// typescript
|
|
1891
1885
|
return {
|
|
1892
|
-
value: createAction
|
|
1886
|
+
value: createAction(name, descriptor.value),
|
|
1893
1887
|
enumerable: false,
|
|
1894
1888
|
configurable: true,
|
|
1895
1889
|
writable: true // for typescript, this must be writable, otherwise it cannot inherit :/ (see inheritable actions test)
|
|
@@ -1903,15 +1897,15 @@ function namedActionDecorator$$1(name) {
|
|
|
1903
1897
|
writable: true,
|
|
1904
1898
|
initializer: function () {
|
|
1905
1899
|
// N.B: we can't immediately invoke initializer; this would be wrong
|
|
1906
|
-
return createAction
|
|
1900
|
+
return createAction(name, initializer_1.call(this));
|
|
1907
1901
|
}
|
|
1908
1902
|
};
|
|
1909
1903
|
}
|
|
1910
1904
|
// bound instance methods
|
|
1911
|
-
return actionFieldDecorator
|
|
1905
|
+
return actionFieldDecorator(name).apply(this, arguments);
|
|
1912
1906
|
};
|
|
1913
1907
|
}
|
|
1914
|
-
function actionFieldDecorator
|
|
1908
|
+
function actionFieldDecorator(name) {
|
|
1915
1909
|
// Simple property that writes on first invocation to the current instance
|
|
1916
1910
|
return function (target, prop, descriptor) {
|
|
1917
1911
|
Object.defineProperty(target, prop, {
|
|
@@ -1921,14 +1915,14 @@ function actionFieldDecorator$$1(name) {
|
|
|
1921
1915
|
return undefined;
|
|
1922
1916
|
},
|
|
1923
1917
|
set: function (value) {
|
|
1924
|
-
addHiddenProp
|
|
1918
|
+
addHiddenProp(this, prop, action(name, value));
|
|
1925
1919
|
}
|
|
1926
1920
|
});
|
|
1927
1921
|
};
|
|
1928
1922
|
}
|
|
1929
|
-
function boundActionDecorator
|
|
1923
|
+
function boundActionDecorator(target, propertyName, descriptor, applyToInstance) {
|
|
1930
1924
|
if (applyToInstance === true) {
|
|
1931
|
-
defineBoundAction
|
|
1925
|
+
defineBoundAction(target, propertyName, descriptor.value);
|
|
1932
1926
|
return null;
|
|
1933
1927
|
}
|
|
1934
1928
|
if (descriptor) {
|
|
@@ -1939,7 +1933,7 @@ function boundActionDecorator$$1(target, propertyName, descriptor, applyToInstan
|
|
|
1939
1933
|
configurable: true,
|
|
1940
1934
|
enumerable: false,
|
|
1941
1935
|
get: function () {
|
|
1942
|
-
defineBoundAction
|
|
1936
|
+
defineBoundAction(this, propertyName, descriptor.value || descriptor.initializer.call(this));
|
|
1943
1937
|
return this[propertyName];
|
|
1944
1938
|
},
|
|
1945
1939
|
set: dontReassignFields
|
|
@@ -1950,7 +1944,7 @@ function boundActionDecorator$$1(target, propertyName, descriptor, applyToInstan
|
|
|
1950
1944
|
enumerable: false,
|
|
1951
1945
|
configurable: true,
|
|
1952
1946
|
set: function (v) {
|
|
1953
|
-
defineBoundAction
|
|
1947
|
+
defineBoundAction(this, propertyName, v);
|
|
1954
1948
|
},
|
|
1955
1949
|
get: function () {
|
|
1956
1950
|
return undefined;
|
|
@@ -1958,42 +1952,42 @@ function boundActionDecorator$$1(target, propertyName, descriptor, applyToInstan
|
|
|
1958
1952
|
};
|
|
1959
1953
|
}
|
|
1960
1954
|
|
|
1961
|
-
var action
|
|
1955
|
+
var action = function action(arg1, arg2, arg3, arg4) {
|
|
1962
1956
|
// action(fn() {})
|
|
1963
1957
|
if (arguments.length === 1 && typeof arg1 === "function")
|
|
1964
|
-
return createAction
|
|
1958
|
+
return createAction(arg1.name || "<unnamed action>", arg1);
|
|
1965
1959
|
// action("name", fn() {})
|
|
1966
1960
|
if (arguments.length === 2 && typeof arg2 === "function")
|
|
1967
|
-
return createAction
|
|
1961
|
+
return createAction(arg1, arg2);
|
|
1968
1962
|
// @action("name") fn() {}
|
|
1969
1963
|
if (arguments.length === 1 && typeof arg1 === "string")
|
|
1970
|
-
return namedActionDecorator
|
|
1964
|
+
return namedActionDecorator(arg1);
|
|
1971
1965
|
// @action fn() {}
|
|
1972
1966
|
if (arg4 === true) {
|
|
1973
1967
|
// apply to instance immediately
|
|
1974
|
-
arg1[arg2] = createAction
|
|
1968
|
+
arg1[arg2] = createAction(arg1.name || arg2, arg3.value);
|
|
1975
1969
|
}
|
|
1976
1970
|
else {
|
|
1977
|
-
return namedActionDecorator
|
|
1971
|
+
return namedActionDecorator(arg2).apply(null, arguments);
|
|
1978
1972
|
}
|
|
1979
1973
|
};
|
|
1980
|
-
action
|
|
1981
|
-
function runInAction
|
|
1974
|
+
action.bound = boundActionDecorator;
|
|
1975
|
+
function runInAction(arg1, arg2) {
|
|
1982
1976
|
// TODO: deprecate?
|
|
1983
1977
|
var actionName = typeof arg1 === "string" ? arg1 : arg1.name || "<unnamed action>";
|
|
1984
1978
|
var fn = typeof arg1 === "function" ? arg1 : arg2;
|
|
1985
1979
|
if (process.env.NODE_ENV !== "production") {
|
|
1986
|
-
invariant
|
|
1980
|
+
invariant(typeof fn === "function" && fn.length === 0, "`runInAction` expects a function without arguments");
|
|
1987
1981
|
if (typeof actionName !== "string" || !actionName)
|
|
1988
|
-
fail
|
|
1982
|
+
fail("actions should have valid names, got: '" + actionName + "'");
|
|
1989
1983
|
}
|
|
1990
|
-
return executeAction
|
|
1984
|
+
return executeAction(actionName, fn, this, undefined);
|
|
1991
1985
|
}
|
|
1992
|
-
function isAction
|
|
1986
|
+
function isAction(thing) {
|
|
1993
1987
|
return typeof thing === "function" && thing.isMobxAction === true;
|
|
1994
1988
|
}
|
|
1995
|
-
function defineBoundAction
|
|
1996
|
-
addHiddenProp
|
|
1989
|
+
function defineBoundAction(target, propertyName, fn) {
|
|
1990
|
+
addHiddenProp(target, propertyName, createAction(propertyName, fn.bind(target)));
|
|
1997
1991
|
}
|
|
1998
1992
|
|
|
1999
1993
|
/**
|
|
@@ -2002,18 +1996,18 @@ function defineBoundAction$$1(target, propertyName, fn) {
|
|
|
2002
1996
|
* @param view The reactive view
|
|
2003
1997
|
* @returns disposer function, which can be used to stop the view from being updated in the future.
|
|
2004
1998
|
*/
|
|
2005
|
-
function autorun
|
|
2006
|
-
if (opts === void 0) { opts = EMPTY_OBJECT
|
|
1999
|
+
function autorun(view, opts) {
|
|
2000
|
+
if (opts === void 0) { opts = EMPTY_OBJECT; }
|
|
2007
2001
|
if (process.env.NODE_ENV !== "production") {
|
|
2008
|
-
invariant
|
|
2009
|
-
invariant
|
|
2002
|
+
invariant(typeof view === "function", "Autorun expects a function as first argument");
|
|
2003
|
+
invariant(isAction(view) === false, "Autorun does not accept actions since actions are untrackable");
|
|
2010
2004
|
}
|
|
2011
|
-
var name = (opts && opts.name) || view.name || "Autorun@" + getNextId
|
|
2005
|
+
var name = (opts && opts.name) || view.name || "Autorun@" + getNextId();
|
|
2012
2006
|
var runSync = !opts.scheduler && !opts.delay;
|
|
2013
|
-
var reaction
|
|
2007
|
+
var reaction;
|
|
2014
2008
|
if (runSync) {
|
|
2015
2009
|
// normal autorun
|
|
2016
|
-
reaction
|
|
2010
|
+
reaction = new Reaction(name, function () {
|
|
2017
2011
|
this.track(reactionRunner);
|
|
2018
2012
|
}, opts.onError);
|
|
2019
2013
|
}
|
|
@@ -2021,22 +2015,22 @@ function autorun$$1(view, opts) {
|
|
|
2021
2015
|
var scheduler_1 = createSchedulerFromOptions(opts);
|
|
2022
2016
|
// debounced autorun
|
|
2023
2017
|
var isScheduled_1 = false;
|
|
2024
|
-
reaction
|
|
2018
|
+
reaction = new Reaction(name, function () {
|
|
2025
2019
|
if (!isScheduled_1) {
|
|
2026
2020
|
isScheduled_1 = true;
|
|
2027
2021
|
scheduler_1(function () {
|
|
2028
2022
|
isScheduled_1 = false;
|
|
2029
|
-
if (!reaction
|
|
2030
|
-
reaction
|
|
2023
|
+
if (!reaction.isDisposed)
|
|
2024
|
+
reaction.track(reactionRunner);
|
|
2031
2025
|
});
|
|
2032
2026
|
}
|
|
2033
2027
|
}, opts.onError);
|
|
2034
2028
|
}
|
|
2035
2029
|
function reactionRunner() {
|
|
2036
|
-
view(reaction
|
|
2030
|
+
view(reaction);
|
|
2037
2031
|
}
|
|
2038
|
-
reaction
|
|
2039
|
-
return reaction
|
|
2032
|
+
reaction.schedule();
|
|
2033
|
+
return reaction.getDisposer();
|
|
2040
2034
|
}
|
|
2041
2035
|
var run = function (f) { return f(); };
|
|
2042
2036
|
function createSchedulerFromOptions(opts) {
|
|
@@ -2046,27 +2040,27 @@ function createSchedulerFromOptions(opts) {
|
|
|
2046
2040
|
? function (f) { return setTimeout(f, opts.delay); }
|
|
2047
2041
|
: run;
|
|
2048
2042
|
}
|
|
2049
|
-
function reaction
|
|
2050
|
-
if (opts === void 0) { opts = EMPTY_OBJECT
|
|
2043
|
+
function reaction(expression, effect, opts) {
|
|
2044
|
+
if (opts === void 0) { opts = EMPTY_OBJECT; }
|
|
2051
2045
|
if (typeof opts === "boolean") {
|
|
2052
2046
|
opts = { fireImmediately: opts };
|
|
2053
|
-
deprecated
|
|
2047
|
+
deprecated("Using fireImmediately as argument is deprecated. Use '{ fireImmediately: true }' instead");
|
|
2054
2048
|
}
|
|
2055
2049
|
if (process.env.NODE_ENV !== "production") {
|
|
2056
|
-
invariant
|
|
2057
|
-
invariant
|
|
2050
|
+
invariant(typeof expression === "function", "First argument to reaction should be a function");
|
|
2051
|
+
invariant(typeof opts === "object", "Third argument of reactions should be an object");
|
|
2058
2052
|
}
|
|
2059
|
-
var name = opts.name || "Reaction@" + getNextId
|
|
2060
|
-
var effectAction = action
|
|
2053
|
+
var name = opts.name || "Reaction@" + getNextId();
|
|
2054
|
+
var effectAction = action(name, opts.onError ? wrapErrorHandler(opts.onError, effect) : effect);
|
|
2061
2055
|
var runSync = !opts.scheduler && !opts.delay;
|
|
2062
2056
|
var scheduler = createSchedulerFromOptions(opts);
|
|
2063
2057
|
var firstTime = true;
|
|
2064
2058
|
var isScheduled = false;
|
|
2065
2059
|
var value;
|
|
2066
2060
|
var equals = opts.compareStructural
|
|
2067
|
-
? comparer
|
|
2068
|
-
: opts.equals || comparer
|
|
2069
|
-
var r = new Reaction
|
|
2061
|
+
? comparer.structural
|
|
2062
|
+
: opts.equals || comparer.default;
|
|
2063
|
+
var r = new Reaction(name, function () {
|
|
2070
2064
|
if (firstTime || runSync) {
|
|
2071
2065
|
reactionRunner();
|
|
2072
2066
|
}
|
|
@@ -2106,18 +2100,18 @@ function wrapErrorHandler(errorHandler, baseFn) {
|
|
|
2106
2100
|
};
|
|
2107
2101
|
}
|
|
2108
2102
|
|
|
2109
|
-
function onBecomeObserved
|
|
2103
|
+
function onBecomeObserved(thing, arg2, arg3) {
|
|
2110
2104
|
return interceptHook("onBecomeObserved", thing, arg2, arg3);
|
|
2111
2105
|
}
|
|
2112
|
-
function onBecomeUnobserved
|
|
2106
|
+
function onBecomeUnobserved(thing, arg2, arg3) {
|
|
2113
2107
|
return interceptHook("onBecomeUnobserved", thing, arg2, arg3);
|
|
2114
2108
|
}
|
|
2115
2109
|
function interceptHook(hook, thing, arg2, arg3) {
|
|
2116
|
-
var atom = typeof arg2 === "string" ? getAtom
|
|
2110
|
+
var atom = typeof arg2 === "string" ? getAtom(thing, arg2) : getAtom(thing);
|
|
2117
2111
|
var cb = typeof arg2 === "string" ? arg3 : arg2;
|
|
2118
2112
|
var orig = atom[hook];
|
|
2119
2113
|
if (typeof orig !== "function")
|
|
2120
|
-
return fail
|
|
2114
|
+
return fail(process.env.NODE_ENV !== "production" && "Not an atom that can be (un)observed");
|
|
2121
2115
|
atom[hook] = function () {
|
|
2122
2116
|
orig.call(this);
|
|
2123
2117
|
cb.call(this);
|
|
@@ -2127,14 +2121,14 @@ function interceptHook(hook, thing, arg2, arg3) {
|
|
|
2127
2121
|
};
|
|
2128
2122
|
}
|
|
2129
2123
|
|
|
2130
|
-
function configure
|
|
2131
|
-
var enforceActions = options.enforceActions, computedRequiresReaction = options.computedRequiresReaction, disableErrorBoundaries = options.disableErrorBoundaries, arrayBuffer = options.arrayBuffer, reactionScheduler = options.reactionScheduler;
|
|
2124
|
+
function configure(options) {
|
|
2125
|
+
var enforceActions = options.enforceActions, computedRequiresReaction = options.computedRequiresReaction, computedConfigurable = options.computedConfigurable, disableErrorBoundaries = options.disableErrorBoundaries, arrayBuffer = options.arrayBuffer, reactionScheduler = options.reactionScheduler;
|
|
2132
2126
|
if (options.isolateGlobalState === true) {
|
|
2133
|
-
isolateGlobalState
|
|
2127
|
+
isolateGlobalState();
|
|
2134
2128
|
}
|
|
2135
2129
|
if (enforceActions !== undefined) {
|
|
2136
2130
|
if (typeof enforceActions === "boolean" || enforceActions === "strict")
|
|
2137
|
-
deprecated
|
|
2131
|
+
deprecated("Deprecated value for 'enforceActions', use 'false' => '\"never\"', 'true' => '\"observed\"', '\"strict\"' => \"'always'\" instead");
|
|
2138
2132
|
var ea = void 0;
|
|
2139
2133
|
switch (enforceActions) {
|
|
2140
2134
|
case true:
|
|
@@ -2150,30 +2144,33 @@ function configure$$1(options) {
|
|
|
2150
2144
|
ea = "strict";
|
|
2151
2145
|
break;
|
|
2152
2146
|
default:
|
|
2153
|
-
fail
|
|
2147
|
+
fail("Invalid value for 'enforceActions': '" + enforceActions + "', expected 'never', 'always' or 'observed'");
|
|
2154
2148
|
}
|
|
2155
|
-
globalState
|
|
2156
|
-
globalState
|
|
2149
|
+
globalState.enforceActions = ea;
|
|
2150
|
+
globalState.allowStateChanges = ea === true || ea === "strict" ? false : true;
|
|
2157
2151
|
}
|
|
2158
2152
|
if (computedRequiresReaction !== undefined) {
|
|
2159
|
-
globalState
|
|
2153
|
+
globalState.computedRequiresReaction = !!computedRequiresReaction;
|
|
2154
|
+
}
|
|
2155
|
+
if (computedConfigurable !== undefined) {
|
|
2156
|
+
globalState.computedConfigurable = !!computedConfigurable;
|
|
2160
2157
|
}
|
|
2161
2158
|
if (disableErrorBoundaries !== undefined) {
|
|
2162
2159
|
if (disableErrorBoundaries === true)
|
|
2163
2160
|
console.warn("WARNING: Debug feature only. MobX will NOT recover from errors if this is on.");
|
|
2164
|
-
globalState
|
|
2161
|
+
globalState.disableErrorBoundaries = !!disableErrorBoundaries;
|
|
2165
2162
|
}
|
|
2166
2163
|
if (typeof arrayBuffer === "number") {
|
|
2167
|
-
reserveArrayBuffer
|
|
2164
|
+
reserveArrayBuffer(arrayBuffer);
|
|
2168
2165
|
}
|
|
2169
2166
|
if (reactionScheduler) {
|
|
2170
|
-
setReactionScheduler
|
|
2167
|
+
setReactionScheduler(reactionScheduler);
|
|
2171
2168
|
}
|
|
2172
2169
|
}
|
|
2173
2170
|
|
|
2174
|
-
function decorate
|
|
2175
|
-
if (process.env.NODE_ENV !== "production" && !isPlainObject
|
|
2176
|
-
fail
|
|
2171
|
+
function decorate(thing, decorators) {
|
|
2172
|
+
if (process.env.NODE_ENV !== "production" && !isPlainObject(decorators))
|
|
2173
|
+
fail("Decorators should be a key value map");
|
|
2177
2174
|
var target = typeof thing === "function" ? thing.prototype : thing;
|
|
2178
2175
|
var _loop_1 = function (prop) {
|
|
2179
2176
|
var propertyDecorators = decorators[prop];
|
|
@@ -2182,7 +2179,7 @@ function decorate$$1(thing, decorators) {
|
|
|
2182
2179
|
}
|
|
2183
2180
|
// prettier-ignore
|
|
2184
2181
|
if (process.env.NODE_ENV !== "production" && !propertyDecorators.every(function (decorator) { return typeof decorator === "function"; }))
|
|
2185
|
-
fail
|
|
2182
|
+
fail("Decorate: expected a decorator function or array of decorator functions for '" + prop + "'");
|
|
2186
2183
|
var descriptor = Object.getOwnPropertyDescriptor(target, prop);
|
|
2187
2184
|
var newDescriptor = propertyDecorators.reduce(function (accDescriptor, decorator) { return decorator(target, prop, accDescriptor); }, descriptor);
|
|
2188
2185
|
if (newDescriptor)
|
|
@@ -2194,42 +2191,42 @@ function decorate$$1(thing, decorators) {
|
|
|
2194
2191
|
return thing;
|
|
2195
2192
|
}
|
|
2196
2193
|
|
|
2197
|
-
function extendShallowObservable
|
|
2198
|
-
deprecated
|
|
2199
|
-
return extendObservable
|
|
2194
|
+
function extendShallowObservable(target, properties, decorators) {
|
|
2195
|
+
deprecated("'extendShallowObservable' is deprecated, use 'extendObservable(target, props, { deep: false })' instead");
|
|
2196
|
+
return extendObservable(target, properties, decorators, shallowCreateObservableOptions);
|
|
2200
2197
|
}
|
|
2201
|
-
function extendObservable
|
|
2198
|
+
function extendObservable(target, properties, decorators, options) {
|
|
2202
2199
|
if (process.env.NODE_ENV !== "production") {
|
|
2203
|
-
invariant
|
|
2204
|
-
invariant
|
|
2205
|
-
invariant
|
|
2206
|
-
invariant
|
|
2200
|
+
invariant(arguments.length >= 2 && arguments.length <= 4, "'extendObservable' expected 2-4 arguments");
|
|
2201
|
+
invariant(typeof target === "object", "'extendObservable' expects an object as first argument");
|
|
2202
|
+
invariant(!isObservableMap(target), "'extendObservable' should not be used on maps, use map.merge instead");
|
|
2203
|
+
invariant(!isObservable(properties), "Extending an object with another observable (object) is not supported. Please construct an explicit propertymap, using `toJS` if need. See issue #540");
|
|
2207
2204
|
if (decorators)
|
|
2208
2205
|
for (var key in decorators)
|
|
2209
2206
|
if (!(key in properties))
|
|
2210
|
-
fail
|
|
2207
|
+
fail("Trying to declare a decorator for unspecified property '" + key + "'");
|
|
2211
2208
|
}
|
|
2212
|
-
options = asCreateObservableOptions
|
|
2213
|
-
var defaultDecorator = options.defaultDecorator || (options.deep === false ? refDecorator
|
|
2214
|
-
initializeInstance
|
|
2215
|
-
asObservableObject
|
|
2216
|
-
startBatch
|
|
2209
|
+
options = asCreateObservableOptions(options);
|
|
2210
|
+
var defaultDecorator = options.defaultDecorator || (options.deep === false ? refDecorator : deepDecorator);
|
|
2211
|
+
initializeInstance(target);
|
|
2212
|
+
asObservableObject(target, options.name, defaultDecorator.enhancer); // make sure object is observable, even without initial props
|
|
2213
|
+
startBatch();
|
|
2217
2214
|
try {
|
|
2218
2215
|
for (var key in properties) {
|
|
2219
2216
|
var descriptor = Object.getOwnPropertyDescriptor(properties, key);
|
|
2220
2217
|
if (process.env.NODE_ENV !== "production") {
|
|
2221
2218
|
if (Object.getOwnPropertyDescriptor(target, key))
|
|
2222
|
-
fail
|
|
2223
|
-
if (isComputed
|
|
2224
|
-
fail
|
|
2219
|
+
fail("'extendObservable' can only be used to introduce new properties. Use 'set' or 'decorate' instead. The property '" + key + "' already exists on '" + target + "'");
|
|
2220
|
+
if (isComputed(descriptor.value))
|
|
2221
|
+
fail("Passing a 'computed' as initial property value is no longer supported by extendObservable. Use a getter or decorator instead");
|
|
2225
2222
|
}
|
|
2226
2223
|
var decorator = decorators && key in decorators
|
|
2227
2224
|
? decorators[key]
|
|
2228
2225
|
: descriptor.get
|
|
2229
|
-
? computedDecorator
|
|
2226
|
+
? computedDecorator
|
|
2230
2227
|
: defaultDecorator;
|
|
2231
2228
|
if (process.env.NODE_ENV !== "production" && typeof decorator !== "function")
|
|
2232
|
-
return fail
|
|
2229
|
+
return fail("Not a valid decorator for '" + key + "', got: " + decorator);
|
|
2233
2230
|
var resultDescriptor = decorator(target, key, descriptor, true);
|
|
2234
2231
|
if (resultDescriptor // otherwise, assume already applied, due to `applyToInstance`
|
|
2235
2232
|
)
|
|
@@ -2237,45 +2234,45 @@ function extendObservable$$1(target, properties, decorators, options) {
|
|
|
2237
2234
|
}
|
|
2238
2235
|
}
|
|
2239
2236
|
finally {
|
|
2240
|
-
endBatch
|
|
2237
|
+
endBatch();
|
|
2241
2238
|
}
|
|
2242
2239
|
return target;
|
|
2243
2240
|
}
|
|
2244
2241
|
|
|
2245
|
-
function getDependencyTree
|
|
2246
|
-
return nodeToDependencyTree(getAtom
|
|
2242
|
+
function getDependencyTree(thing, property) {
|
|
2243
|
+
return nodeToDependencyTree(getAtom(thing, property));
|
|
2247
2244
|
}
|
|
2248
2245
|
function nodeToDependencyTree(node) {
|
|
2249
2246
|
var result = {
|
|
2250
2247
|
name: node.name
|
|
2251
2248
|
};
|
|
2252
2249
|
if (node.observing && node.observing.length > 0)
|
|
2253
|
-
result.dependencies = unique
|
|
2250
|
+
result.dependencies = unique(node.observing).map(nodeToDependencyTree);
|
|
2254
2251
|
return result;
|
|
2255
2252
|
}
|
|
2256
|
-
function getObserverTree
|
|
2257
|
-
return nodeToObserverTree(getAtom
|
|
2253
|
+
function getObserverTree(thing, property) {
|
|
2254
|
+
return nodeToObserverTree(getAtom(thing, property));
|
|
2258
2255
|
}
|
|
2259
2256
|
function nodeToObserverTree(node) {
|
|
2260
2257
|
var result = {
|
|
2261
2258
|
name: node.name
|
|
2262
2259
|
};
|
|
2263
|
-
if (hasObservers
|
|
2264
|
-
result.observers = getObservers
|
|
2260
|
+
if (hasObservers(node))
|
|
2261
|
+
result.observers = getObservers(node).map(nodeToObserverTree);
|
|
2265
2262
|
return result;
|
|
2266
2263
|
}
|
|
2267
2264
|
|
|
2268
2265
|
var generatorId = 0;
|
|
2269
|
-
function flow
|
|
2266
|
+
function flow(generator) {
|
|
2270
2267
|
if (arguments.length !== 1)
|
|
2271
|
-
fail
|
|
2268
|
+
fail(!!process.env.NODE_ENV && "Flow expects one 1 argument and cannot be used as decorator");
|
|
2272
2269
|
var name = generator.name || "<unnamed flow>";
|
|
2273
2270
|
// Implementation based on https://github.com/tj/co/blob/master/index.js
|
|
2274
2271
|
return function () {
|
|
2275
2272
|
var ctx = this;
|
|
2276
2273
|
var args = arguments;
|
|
2277
2274
|
var runId = ++generatorId;
|
|
2278
|
-
var gen = action
|
|
2275
|
+
var gen = action(name + " - runid: " + runId + " - init", generator).apply(ctx, args);
|
|
2279
2276
|
var rejector;
|
|
2280
2277
|
var pendingPromise = undefined;
|
|
2281
2278
|
var res = new Promise(function (resolve, reject) {
|
|
@@ -2285,7 +2282,7 @@ function flow$$1(generator) {
|
|
|
2285
2282
|
pendingPromise = undefined;
|
|
2286
2283
|
var ret;
|
|
2287
2284
|
try {
|
|
2288
|
-
ret = action
|
|
2285
|
+
ret = action(name + " - runid: " + runId + " - yield " + stepId++, gen.next).call(gen, res);
|
|
2289
2286
|
}
|
|
2290
2287
|
catch (e) {
|
|
2291
2288
|
return reject(e);
|
|
@@ -2296,7 +2293,7 @@ function flow$$1(generator) {
|
|
|
2296
2293
|
pendingPromise = undefined;
|
|
2297
2294
|
var ret;
|
|
2298
2295
|
try {
|
|
2299
|
-
ret = action
|
|
2296
|
+
ret = action(name + " - runid: " + runId + " - yield " + stepId++, gen.throw).call(gen, err);
|
|
2300
2297
|
}
|
|
2301
2298
|
catch (e) {
|
|
2302
2299
|
return reject(e);
|
|
@@ -2316,7 +2313,7 @@ function flow$$1(generator) {
|
|
|
2316
2313
|
}
|
|
2317
2314
|
onFulfilled(undefined); // kick off the process
|
|
2318
2315
|
});
|
|
2319
|
-
res.cancel = action
|
|
2316
|
+
res.cancel = action(name + " - runid: " + runId + " - cancel", function () {
|
|
2320
2317
|
try {
|
|
2321
2318
|
if (pendingPromise)
|
|
2322
2319
|
cancelPromise(pendingPromise);
|
|
@@ -2324,7 +2321,7 @@ function flow$$1(generator) {
|
|
|
2324
2321
|
var res_1 = gen.return();
|
|
2325
2322
|
// eat anything that promise would do, it's cancelled!
|
|
2326
2323
|
var yieldedPromise = Promise.resolve(res_1.value);
|
|
2327
|
-
yieldedPromise.then(noop
|
|
2324
|
+
yieldedPromise.then(noop, noop);
|
|
2328
2325
|
cancelPromise(yieldedPromise); // maybe it can be cancelled :)
|
|
2329
2326
|
// reject our original promise
|
|
2330
2327
|
rejector(new Error("FLOW_CANCELLED"));
|
|
@@ -2341,66 +2338,66 @@ function cancelPromise(promise) {
|
|
|
2341
2338
|
promise.cancel();
|
|
2342
2339
|
}
|
|
2343
2340
|
|
|
2344
|
-
function interceptReads
|
|
2341
|
+
function interceptReads(thing, propOrHandler, handler) {
|
|
2345
2342
|
var target;
|
|
2346
|
-
if (isObservableMap
|
|
2347
|
-
target = getAdministration
|
|
2343
|
+
if (isObservableMap(thing) || isObservableArray(thing) || isObservableValue(thing)) {
|
|
2344
|
+
target = getAdministration(thing);
|
|
2348
2345
|
}
|
|
2349
|
-
else if (isObservableObject
|
|
2346
|
+
else if (isObservableObject(thing)) {
|
|
2350
2347
|
if (typeof propOrHandler !== "string")
|
|
2351
|
-
return fail
|
|
2348
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2352
2349
|
"InterceptReads can only be used with a specific property, not with an object in general");
|
|
2353
|
-
target = getAdministration
|
|
2350
|
+
target = getAdministration(thing, propOrHandler);
|
|
2354
2351
|
}
|
|
2355
2352
|
else {
|
|
2356
|
-
return fail
|
|
2353
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2357
2354
|
"Expected observable map, object or array as first array");
|
|
2358
2355
|
}
|
|
2359
2356
|
if (target.dehancer !== undefined)
|
|
2360
|
-
return fail
|
|
2357
|
+
return fail(process.env.NODE_ENV !== "production" && "An intercept reader was already established");
|
|
2361
2358
|
target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler;
|
|
2362
2359
|
return function () {
|
|
2363
2360
|
target.dehancer = undefined;
|
|
2364
2361
|
};
|
|
2365
2362
|
}
|
|
2366
2363
|
|
|
2367
|
-
function intercept
|
|
2364
|
+
function intercept(thing, propOrHandler, handler) {
|
|
2368
2365
|
if (typeof handler === "function")
|
|
2369
2366
|
return interceptProperty(thing, propOrHandler, handler);
|
|
2370
2367
|
else
|
|
2371
2368
|
return interceptInterceptable(thing, propOrHandler);
|
|
2372
2369
|
}
|
|
2373
2370
|
function interceptInterceptable(thing, handler) {
|
|
2374
|
-
return getAdministration
|
|
2371
|
+
return getAdministration(thing).intercept(handler);
|
|
2375
2372
|
}
|
|
2376
2373
|
function interceptProperty(thing, property, handler) {
|
|
2377
|
-
return getAdministration
|
|
2374
|
+
return getAdministration(thing, property).intercept(handler);
|
|
2378
2375
|
}
|
|
2379
2376
|
|
|
2380
|
-
function _isComputed
|
|
2377
|
+
function _isComputed(value, property) {
|
|
2381
2378
|
if (value === null || value === undefined)
|
|
2382
2379
|
return false;
|
|
2383
2380
|
if (property !== undefined) {
|
|
2384
|
-
if (isObservableObject
|
|
2381
|
+
if (isObservableObject(value) === false)
|
|
2385
2382
|
return false;
|
|
2386
2383
|
if (!value.$mobx.values[property])
|
|
2387
2384
|
return false;
|
|
2388
|
-
var atom = getAtom
|
|
2389
|
-
return isComputedValue
|
|
2385
|
+
var atom = getAtom(value, property);
|
|
2386
|
+
return isComputedValue(atom);
|
|
2390
2387
|
}
|
|
2391
|
-
return isComputedValue
|
|
2388
|
+
return isComputedValue(value);
|
|
2392
2389
|
}
|
|
2393
|
-
function isComputed
|
|
2390
|
+
function isComputed(value) {
|
|
2394
2391
|
if (arguments.length > 1)
|
|
2395
|
-
return fail
|
|
2392
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2396
2393
|
"isComputed expects only 1 argument. Use isObservableProp to inspect the observability of a property");
|
|
2397
|
-
return _isComputed
|
|
2394
|
+
return _isComputed(value);
|
|
2398
2395
|
}
|
|
2399
|
-
function isComputedProp
|
|
2396
|
+
function isComputedProp(value, propName) {
|
|
2400
2397
|
if (typeof propName !== "string")
|
|
2401
|
-
return fail
|
|
2398
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2402
2399
|
"isComputed expected a property name as second argument");
|
|
2403
|
-
return _isComputed
|
|
2400
|
+
return _isComputed(value, propName);
|
|
2404
2401
|
}
|
|
2405
2402
|
|
|
2406
2403
|
function _isObservable(value, property) {
|
|
@@ -2408,194 +2405,196 @@ function _isObservable(value, property) {
|
|
|
2408
2405
|
return false;
|
|
2409
2406
|
if (property !== undefined) {
|
|
2410
2407
|
if (process.env.NODE_ENV !== "production" &&
|
|
2411
|
-
(isObservableMap
|
|
2412
|
-
return fail
|
|
2413
|
-
if (isObservableObject
|
|
2408
|
+
(isObservableMap(value) || isObservableArray(value)))
|
|
2409
|
+
return fail("isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.");
|
|
2410
|
+
if (isObservableObject(value)) {
|
|
2414
2411
|
var o = value.$mobx;
|
|
2415
2412
|
return o.values && !!o.values[property];
|
|
2416
2413
|
}
|
|
2417
2414
|
return false;
|
|
2418
2415
|
}
|
|
2419
2416
|
// For first check, see #701
|
|
2420
|
-
return (isObservableObject
|
|
2417
|
+
return (isObservableObject(value) ||
|
|
2421
2418
|
!!value.$mobx ||
|
|
2422
|
-
isAtom
|
|
2423
|
-
isReaction
|
|
2424
|
-
isComputedValue
|
|
2419
|
+
isAtom(value) ||
|
|
2420
|
+
isReaction(value) ||
|
|
2421
|
+
isComputedValue(value));
|
|
2425
2422
|
}
|
|
2426
|
-
function isObservable
|
|
2423
|
+
function isObservable(value) {
|
|
2427
2424
|
if (arguments.length !== 1)
|
|
2428
|
-
fail
|
|
2425
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
2429
2426
|
"isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property");
|
|
2430
2427
|
return _isObservable(value);
|
|
2431
2428
|
}
|
|
2432
|
-
function isObservableProp
|
|
2429
|
+
function isObservableProp(value, propName) {
|
|
2433
2430
|
if (typeof propName !== "string")
|
|
2434
|
-
return fail
|
|
2431
|
+
return fail(process.env.NODE_ENV !== "production" && "expected a property name as second argument");
|
|
2435
2432
|
return _isObservable(value, propName);
|
|
2436
2433
|
}
|
|
2437
2434
|
|
|
2438
|
-
function keys
|
|
2439
|
-
if (isObservableObject
|
|
2435
|
+
function keys(obj) {
|
|
2436
|
+
if (isObservableObject(obj)) {
|
|
2440
2437
|
return obj.$mobx.getKeys();
|
|
2441
2438
|
}
|
|
2442
|
-
if (isObservableMap
|
|
2439
|
+
if (isObservableMap(obj)) {
|
|
2443
2440
|
return obj._keys.slice();
|
|
2444
2441
|
}
|
|
2445
|
-
if (isObservableSet
|
|
2446
|
-
return iteratorToArray
|
|
2442
|
+
if (isObservableSet(obj)) {
|
|
2443
|
+
return iteratorToArray(obj.keys());
|
|
2447
2444
|
}
|
|
2448
|
-
if (isObservableArray
|
|
2445
|
+
if (isObservableArray(obj)) {
|
|
2449
2446
|
return obj.map(function (_, index) { return index; });
|
|
2450
2447
|
}
|
|
2451
|
-
return fail
|
|
2448
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2452
2449
|
"'keys()' can only be used on observable objects, arrays, sets and maps");
|
|
2453
2450
|
}
|
|
2454
|
-
function values
|
|
2455
|
-
if (isObservableObject
|
|
2456
|
-
return keys
|
|
2451
|
+
function values(obj) {
|
|
2452
|
+
if (isObservableObject(obj)) {
|
|
2453
|
+
return keys(obj).map(function (key) { return obj[key]; });
|
|
2457
2454
|
}
|
|
2458
|
-
if (isObservableMap
|
|
2459
|
-
return keys
|
|
2455
|
+
if (isObservableMap(obj)) {
|
|
2456
|
+
return keys(obj).map(function (key) { return obj.get(key); });
|
|
2460
2457
|
}
|
|
2461
|
-
if (isObservableSet
|
|
2462
|
-
return iteratorToArray
|
|
2458
|
+
if (isObservableSet(obj)) {
|
|
2459
|
+
return iteratorToArray(obj.values());
|
|
2463
2460
|
}
|
|
2464
|
-
if (isObservableArray
|
|
2461
|
+
if (isObservableArray(obj)) {
|
|
2465
2462
|
return obj.slice();
|
|
2466
2463
|
}
|
|
2467
|
-
return fail
|
|
2464
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2468
2465
|
"'values()' can only be used on observable objects, arrays, sets and maps");
|
|
2469
2466
|
}
|
|
2470
|
-
function entries
|
|
2471
|
-
if (isObservableObject
|
|
2472
|
-
return keys
|
|
2467
|
+
function entries(obj) {
|
|
2468
|
+
if (isObservableObject(obj)) {
|
|
2469
|
+
return keys(obj).map(function (key) { return [key, obj[key]]; });
|
|
2473
2470
|
}
|
|
2474
|
-
if (isObservableMap
|
|
2475
|
-
return keys
|
|
2471
|
+
if (isObservableMap(obj)) {
|
|
2472
|
+
return keys(obj).map(function (key) { return [key, obj.get(key)]; });
|
|
2476
2473
|
}
|
|
2477
|
-
if (isObservableSet
|
|
2478
|
-
return iteratorToArray
|
|
2474
|
+
if (isObservableSet(obj)) {
|
|
2475
|
+
return iteratorToArray(obj.entries());
|
|
2479
2476
|
}
|
|
2480
|
-
if (isObservableArray
|
|
2477
|
+
if (isObservableArray(obj)) {
|
|
2481
2478
|
return obj.map(function (key, index) { return [index, key]; });
|
|
2482
2479
|
}
|
|
2483
|
-
return fail
|
|
2480
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2484
2481
|
"'entries()' can only be used on observable objects, arrays and maps");
|
|
2485
2482
|
}
|
|
2486
|
-
function set
|
|
2487
|
-
if (arguments.length === 2) {
|
|
2488
|
-
startBatch
|
|
2483
|
+
function set(obj, key, value) {
|
|
2484
|
+
if (arguments.length === 2 && !isObservableSet(obj)) {
|
|
2485
|
+
startBatch();
|
|
2489
2486
|
var values_1 = key;
|
|
2490
2487
|
try {
|
|
2491
2488
|
for (var key_1 in values_1)
|
|
2492
|
-
set
|
|
2489
|
+
set(obj, key_1, values_1[key_1]);
|
|
2493
2490
|
}
|
|
2494
2491
|
finally {
|
|
2495
|
-
endBatch
|
|
2492
|
+
endBatch();
|
|
2496
2493
|
}
|
|
2497
2494
|
return;
|
|
2498
2495
|
}
|
|
2499
|
-
if (isObservableObject
|
|
2496
|
+
if (isObservableObject(obj)) {
|
|
2500
2497
|
var adm = obj.$mobx;
|
|
2501
2498
|
var existingObservable = adm.values[key];
|
|
2502
2499
|
if (existingObservable) {
|
|
2503
2500
|
adm.write(obj, key, value);
|
|
2504
2501
|
}
|
|
2505
2502
|
else {
|
|
2506
|
-
defineObservableProperty
|
|
2503
|
+
defineObservableProperty(obj, key, value, adm.defaultEnhancer);
|
|
2507
2504
|
}
|
|
2508
2505
|
}
|
|
2509
|
-
else if (isObservableMap
|
|
2506
|
+
else if (isObservableMap(obj)) {
|
|
2510
2507
|
obj.set(key, value);
|
|
2511
2508
|
}
|
|
2512
|
-
else if (
|
|
2509
|
+
else if (isObservableSet(obj)) {
|
|
2510
|
+
obj.add(key);
|
|
2511
|
+
}
|
|
2512
|
+
else if (isObservableArray(obj)) {
|
|
2513
2513
|
if (typeof key !== "number")
|
|
2514
2514
|
key = parseInt(key, 10);
|
|
2515
|
-
invariant
|
|
2516
|
-
startBatch
|
|
2515
|
+
invariant(key >= 0, "Not a valid index: '" + key + "'");
|
|
2516
|
+
startBatch();
|
|
2517
2517
|
if (key >= obj.length)
|
|
2518
2518
|
obj.length = key + 1;
|
|
2519
2519
|
obj[key] = value;
|
|
2520
|
-
endBatch
|
|
2520
|
+
endBatch();
|
|
2521
2521
|
}
|
|
2522
2522
|
else {
|
|
2523
|
-
return fail
|
|
2523
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2524
2524
|
"'set()' can only be used on observable objects, arrays and maps");
|
|
2525
2525
|
}
|
|
2526
2526
|
}
|
|
2527
|
-
function remove
|
|
2528
|
-
if (isObservableObject
|
|
2529
|
-
|
|
2527
|
+
function remove(obj, key) {
|
|
2528
|
+
if (isObservableObject(obj)) {
|
|
2530
2529
|
obj.$mobx.remove(key);
|
|
2531
2530
|
}
|
|
2532
|
-
else if (isObservableMap
|
|
2531
|
+
else if (isObservableMap(obj)) {
|
|
2533
2532
|
obj.delete(key);
|
|
2534
2533
|
}
|
|
2535
|
-
else if (isObservableSet
|
|
2534
|
+
else if (isObservableSet(obj)) {
|
|
2536
2535
|
obj.delete(key);
|
|
2537
2536
|
}
|
|
2538
|
-
else if (isObservableArray
|
|
2537
|
+
else if (isObservableArray(obj)) {
|
|
2539
2538
|
if (typeof key !== "number")
|
|
2540
2539
|
key = parseInt(key, 10);
|
|
2541
|
-
invariant
|
|
2540
|
+
invariant(key >= 0, "Not a valid index: '" + key + "'");
|
|
2542
2541
|
obj.splice(key, 1);
|
|
2543
2542
|
}
|
|
2544
2543
|
else {
|
|
2545
|
-
return fail
|
|
2544
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2546
2545
|
"'remove()' can only be used on observable objects, arrays and maps");
|
|
2547
2546
|
}
|
|
2548
2547
|
}
|
|
2549
|
-
function has
|
|
2550
|
-
if (isObservableObject
|
|
2548
|
+
function has(obj, key) {
|
|
2549
|
+
if (isObservableObject(obj)) {
|
|
2551
2550
|
// return keys(obj).indexOf(key) >= 0
|
|
2552
|
-
var adm = getAdministration
|
|
2551
|
+
var adm = getAdministration(obj);
|
|
2553
2552
|
adm.getKeys(); // make sure we get notified of key changes, but for performance, use the values map to look up existence
|
|
2554
2553
|
return !!adm.values[key];
|
|
2555
2554
|
}
|
|
2556
|
-
else if (isObservableMap
|
|
2555
|
+
else if (isObservableMap(obj)) {
|
|
2557
2556
|
return obj.has(key);
|
|
2558
2557
|
}
|
|
2559
|
-
else if (isObservableSet
|
|
2558
|
+
else if (isObservableSet(obj)) {
|
|
2560
2559
|
return obj.has(key);
|
|
2561
2560
|
}
|
|
2562
|
-
else if (isObservableArray
|
|
2561
|
+
else if (isObservableArray(obj)) {
|
|
2563
2562
|
return key >= 0 && key < obj.length;
|
|
2564
2563
|
}
|
|
2565
2564
|
else {
|
|
2566
|
-
return fail
|
|
2565
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2567
2566
|
"'has()' can only be used on observable objects, arrays and maps");
|
|
2568
2567
|
}
|
|
2569
2568
|
}
|
|
2570
|
-
function get
|
|
2571
|
-
if (!has
|
|
2569
|
+
function get(obj, key) {
|
|
2570
|
+
if (!has(obj, key))
|
|
2572
2571
|
return undefined;
|
|
2573
|
-
if (isObservableObject
|
|
2572
|
+
if (isObservableObject(obj)) {
|
|
2574
2573
|
return obj[key];
|
|
2575
2574
|
}
|
|
2576
|
-
else if (isObservableMap
|
|
2575
|
+
else if (isObservableMap(obj)) {
|
|
2577
2576
|
return obj.get(key);
|
|
2578
2577
|
}
|
|
2579
|
-
else if (isObservableArray
|
|
2578
|
+
else if (isObservableArray(obj)) {
|
|
2580
2579
|
return obj[key];
|
|
2581
2580
|
}
|
|
2582
2581
|
else {
|
|
2583
|
-
return fail
|
|
2582
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2584
2583
|
"'get()' can only be used on observable objects, arrays and maps");
|
|
2585
2584
|
}
|
|
2586
2585
|
}
|
|
2587
2586
|
|
|
2588
|
-
function observe
|
|
2587
|
+
function observe(thing, propOrCb, cbOrFire, fireImmediately) {
|
|
2589
2588
|
if (typeof cbOrFire === "function")
|
|
2590
2589
|
return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);
|
|
2591
2590
|
else
|
|
2592
2591
|
return observeObservable(thing, propOrCb, cbOrFire);
|
|
2593
2592
|
}
|
|
2594
2593
|
function observeObservable(thing, listener, fireImmediately) {
|
|
2595
|
-
return getAdministration
|
|
2594
|
+
return getAdministration(thing).observe(listener, fireImmediately);
|
|
2596
2595
|
}
|
|
2597
2596
|
function observeObservableProperty(thing, property, listener, fireImmediately) {
|
|
2598
|
-
return getAdministration
|
|
2597
|
+
return getAdministration(thing, property).observe(listener, fireImmediately);
|
|
2599
2598
|
}
|
|
2600
2599
|
|
|
2601
2600
|
var defaultOptions = {
|
|
@@ -2609,7 +2608,7 @@ function cache(map, key, value, options) {
|
|
|
2609
2608
|
return value;
|
|
2610
2609
|
}
|
|
2611
2610
|
function toJSHelper(source, options, __alreadySeen) {
|
|
2612
|
-
if (!options.recurseEverything && !isObservable
|
|
2611
|
+
if (!options.recurseEverything && !isObservable(source))
|
|
2613
2612
|
return source;
|
|
2614
2613
|
if (typeof source !== "object")
|
|
2615
2614
|
return source;
|
|
@@ -2619,16 +2618,16 @@ function toJSHelper(source, options, __alreadySeen) {
|
|
|
2619
2618
|
// Directly return the Date object itself if contained in the observable
|
|
2620
2619
|
if (source instanceof Date)
|
|
2621
2620
|
return source;
|
|
2622
|
-
if (isObservableValue
|
|
2621
|
+
if (isObservableValue(source))
|
|
2623
2622
|
return toJSHelper(source.get(), options, __alreadySeen);
|
|
2624
2623
|
// make sure we track the keys of the object
|
|
2625
|
-
if (isObservable
|
|
2626
|
-
keys
|
|
2624
|
+
if (isObservable(source))
|
|
2625
|
+
keys(source);
|
|
2627
2626
|
var detectCycles = options.detectCycles === true;
|
|
2628
2627
|
if (detectCycles && source !== null && __alreadySeen.has(source)) {
|
|
2629
2628
|
return __alreadySeen.get(source);
|
|
2630
2629
|
}
|
|
2631
|
-
if (isObservableArray
|
|
2630
|
+
if (isObservableArray(source) || Array.isArray(source)) {
|
|
2632
2631
|
var res_1 = cache(__alreadySeen, source, [], options);
|
|
2633
2632
|
var toAdd = source.map(function (value) { return toJSHelper(value, options, __alreadySeen); });
|
|
2634
2633
|
res_1.length = toAdd.length;
|
|
@@ -2636,7 +2635,7 @@ function toJSHelper(source, options, __alreadySeen) {
|
|
|
2636
2635
|
res_1[i] = toAdd[i];
|
|
2637
2636
|
return res_1;
|
|
2638
2637
|
}
|
|
2639
|
-
if (isObservableSet
|
|
2638
|
+
if (isObservableSet(source) || Object.getPrototypeOf(source) === Set.prototype) {
|
|
2640
2639
|
if (options.exportMapsAsObjects === false) {
|
|
2641
2640
|
var res_2 = cache(__alreadySeen, source, new Set(), options);
|
|
2642
2641
|
source.forEach(function (value) {
|
|
@@ -2652,7 +2651,7 @@ function toJSHelper(source, options, __alreadySeen) {
|
|
|
2652
2651
|
return res_3;
|
|
2653
2652
|
}
|
|
2654
2653
|
}
|
|
2655
|
-
if (isObservableMap
|
|
2654
|
+
if (isObservableMap(source) || Object.getPrototypeOf(source) === Map.prototype) {
|
|
2656
2655
|
if (options.exportMapsAsObjects === false) {
|
|
2657
2656
|
var res_4 = cache(__alreadySeen, source, new Map(), options);
|
|
2658
2657
|
source.forEach(function (value, key) {
|
|
@@ -2675,7 +2674,7 @@ function toJSHelper(source, options, __alreadySeen) {
|
|
|
2675
2674
|
}
|
|
2676
2675
|
return res;
|
|
2677
2676
|
}
|
|
2678
|
-
function toJS
|
|
2677
|
+
function toJS(source, options) {
|
|
2679
2678
|
// backward compatibility
|
|
2680
2679
|
if (typeof options === "boolean")
|
|
2681
2680
|
options = { detectCycles: options };
|
|
@@ -2691,7 +2690,7 @@ function toJS$$1(source, options) {
|
|
|
2691
2690
|
return toJSHelper(source, options, __alreadySeen);
|
|
2692
2691
|
}
|
|
2693
2692
|
|
|
2694
|
-
function trace
|
|
2693
|
+
function trace() {
|
|
2695
2694
|
var args = [];
|
|
2696
2695
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2697
2696
|
args[_i] = arguments[_i];
|
|
@@ -2701,22 +2700,22 @@ function trace$$1() {
|
|
|
2701
2700
|
enterBreakPoint = args.pop();
|
|
2702
2701
|
var derivation = getAtomFromArgs(args);
|
|
2703
2702
|
if (!derivation) {
|
|
2704
|
-
return fail
|
|
2703
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2705
2704
|
"'trace(break?)' can only be used inside a tracked computed value or a Reaction. Consider passing in the computed value or reaction explicitly");
|
|
2706
2705
|
}
|
|
2707
|
-
if (derivation.isTracing === TraceMode
|
|
2706
|
+
if (derivation.isTracing === TraceMode.NONE) {
|
|
2708
2707
|
console.log("[mobx.trace] '" + derivation.name + "' tracing enabled");
|
|
2709
2708
|
}
|
|
2710
|
-
derivation.isTracing = enterBreakPoint ? TraceMode
|
|
2709
|
+
derivation.isTracing = enterBreakPoint ? TraceMode.BREAK : TraceMode.LOG;
|
|
2711
2710
|
}
|
|
2712
2711
|
function getAtomFromArgs(args) {
|
|
2713
2712
|
switch (args.length) {
|
|
2714
2713
|
case 0:
|
|
2715
|
-
return globalState
|
|
2714
|
+
return globalState.trackingDerivation;
|
|
2716
2715
|
case 1:
|
|
2717
|
-
return getAtom
|
|
2716
|
+
return getAtom(args[0]);
|
|
2718
2717
|
case 2:
|
|
2719
|
-
return getAtom
|
|
2718
|
+
return getAtom(args[0], args[1]);
|
|
2720
2719
|
}
|
|
2721
2720
|
}
|
|
2722
2721
|
|
|
@@ -2727,18 +2726,18 @@ function getAtomFromArgs(args) {
|
|
|
2727
2726
|
* @param action a function that updates some reactive state
|
|
2728
2727
|
* @returns any value that was returned by the 'action' parameter.
|
|
2729
2728
|
*/
|
|
2730
|
-
function transaction
|
|
2729
|
+
function transaction(action, thisArg) {
|
|
2731
2730
|
if (thisArg === void 0) { thisArg = undefined; }
|
|
2732
|
-
startBatch
|
|
2731
|
+
startBatch();
|
|
2733
2732
|
try {
|
|
2734
|
-
return action
|
|
2733
|
+
return action.apply(thisArg);
|
|
2735
2734
|
}
|
|
2736
2735
|
finally {
|
|
2737
|
-
endBatch
|
|
2736
|
+
endBatch();
|
|
2738
2737
|
}
|
|
2739
2738
|
}
|
|
2740
2739
|
|
|
2741
|
-
function when
|
|
2740
|
+
function when(predicate, arg1, arg2) {
|
|
2742
2741
|
if (arguments.length === 1 || (arg1 && typeof arg1 === "object"))
|
|
2743
2742
|
return whenPromise(predicate, arg1);
|
|
2744
2743
|
return _when(predicate, arg1, arg2 || {});
|
|
@@ -2757,9 +2756,9 @@ function _when(predicate, effect, opts) {
|
|
|
2757
2756
|
}
|
|
2758
2757
|
}, opts.timeout);
|
|
2759
2758
|
}
|
|
2760
|
-
opts.name = opts.name || "When@" + getNextId
|
|
2761
|
-
var effectAction = createAction
|
|
2762
|
-
var disposer = autorun
|
|
2759
|
+
opts.name = opts.name || "When@" + getNextId();
|
|
2760
|
+
var effectAction = createAction(opts.name + "-effect", effect);
|
|
2761
|
+
var disposer = autorun(function (r) {
|
|
2763
2762
|
if (predicate()) {
|
|
2764
2763
|
r.dispose();
|
|
2765
2764
|
if (timeoutHandle)
|
|
@@ -2771,7 +2770,7 @@ function _when(predicate, effect, opts) {
|
|
|
2771
2770
|
}
|
|
2772
2771
|
function whenPromise(predicate, opts) {
|
|
2773
2772
|
if (process.env.NODE_ENV !== "production" && opts && opts.onError)
|
|
2774
|
-
return fail
|
|
2773
|
+
return fail("the options 'onError' and 'promise' cannot be combined");
|
|
2775
2774
|
var cancel;
|
|
2776
2775
|
var res = new Promise(function (resolve, reject) {
|
|
2777
2776
|
var disposer = _when(predicate, resolve, __assign({}, opts, { onError: reject }));
|
|
@@ -2784,50 +2783,50 @@ function whenPromise(predicate, opts) {
|
|
|
2784
2783
|
return res;
|
|
2785
2784
|
}
|
|
2786
2785
|
|
|
2787
|
-
function hasInterceptors
|
|
2786
|
+
function hasInterceptors(interceptable) {
|
|
2788
2787
|
return interceptable.interceptors !== undefined && interceptable.interceptors.length > 0;
|
|
2789
2788
|
}
|
|
2790
|
-
function registerInterceptor
|
|
2789
|
+
function registerInterceptor(interceptable, handler) {
|
|
2791
2790
|
var interceptors = interceptable.interceptors || (interceptable.interceptors = []);
|
|
2792
2791
|
interceptors.push(handler);
|
|
2793
|
-
return once
|
|
2792
|
+
return once(function () {
|
|
2794
2793
|
var idx = interceptors.indexOf(handler);
|
|
2795
2794
|
if (idx !== -1)
|
|
2796
2795
|
interceptors.splice(idx, 1);
|
|
2797
2796
|
});
|
|
2798
2797
|
}
|
|
2799
|
-
function interceptChange
|
|
2800
|
-
var prevU = untrackedStart
|
|
2798
|
+
function interceptChange(interceptable, change) {
|
|
2799
|
+
var prevU = untrackedStart();
|
|
2801
2800
|
try {
|
|
2802
2801
|
var interceptors = interceptable.interceptors;
|
|
2803
2802
|
if (interceptors)
|
|
2804
2803
|
for (var i = 0, l = interceptors.length; i < l; i++) {
|
|
2805
2804
|
change = interceptors[i](change);
|
|
2806
|
-
invariant
|
|
2805
|
+
invariant(!change || change.type, "Intercept handlers should return nothing or a change object");
|
|
2807
2806
|
if (!change)
|
|
2808
2807
|
break;
|
|
2809
2808
|
}
|
|
2810
2809
|
return change;
|
|
2811
2810
|
}
|
|
2812
2811
|
finally {
|
|
2813
|
-
untrackedEnd
|
|
2812
|
+
untrackedEnd(prevU);
|
|
2814
2813
|
}
|
|
2815
2814
|
}
|
|
2816
2815
|
|
|
2817
|
-
function hasListeners
|
|
2816
|
+
function hasListeners(listenable) {
|
|
2818
2817
|
return listenable.changeListeners !== undefined && listenable.changeListeners.length > 0;
|
|
2819
2818
|
}
|
|
2820
|
-
function registerListener
|
|
2819
|
+
function registerListener(listenable, handler) {
|
|
2821
2820
|
var listeners = listenable.changeListeners || (listenable.changeListeners = []);
|
|
2822
2821
|
listeners.push(handler);
|
|
2823
|
-
return once
|
|
2822
|
+
return once(function () {
|
|
2824
2823
|
var idx = listeners.indexOf(handler);
|
|
2825
2824
|
if (idx !== -1)
|
|
2826
2825
|
listeners.splice(idx, 1);
|
|
2827
2826
|
});
|
|
2828
2827
|
}
|
|
2829
|
-
function notifyListeners
|
|
2830
|
-
var prevU = untrackedStart
|
|
2828
|
+
function notifyListeners(listenable, change) {
|
|
2829
|
+
var prevU = untrackedStart();
|
|
2831
2830
|
var listeners = listenable.changeListeners;
|
|
2832
2831
|
if (!listeners)
|
|
2833
2832
|
return;
|
|
@@ -2835,7 +2834,7 @@ function notifyListeners$$1(listenable, change) {
|
|
|
2835
2834
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
2836
2835
|
listeners[i](change);
|
|
2837
2836
|
}
|
|
2838
|
-
untrackedEnd
|
|
2837
|
+
untrackedEnd(prevU);
|
|
2839
2838
|
}
|
|
2840
2839
|
|
|
2841
2840
|
var MAX_SPLICE_SIZE = 10000; // See e.g. https://github.com/mobxjs/mobx/issues/859
|
|
@@ -2858,10 +2857,10 @@ var safariPrototypeSetterInheritanceBug = (function () {
|
|
|
2858
2857
|
*/
|
|
2859
2858
|
var OBSERVABLE_ARRAY_BUFFER_SIZE = 0;
|
|
2860
2859
|
// Typescript workaround to make sure ObservableArray extends Array
|
|
2861
|
-
var StubArray
|
|
2862
|
-
function StubArray
|
|
2860
|
+
var StubArray = /** @class */ (function () {
|
|
2861
|
+
function StubArray() {
|
|
2863
2862
|
}
|
|
2864
|
-
return StubArray
|
|
2863
|
+
return StubArray;
|
|
2865
2864
|
}());
|
|
2866
2865
|
function inherit(ctor, proto) {
|
|
2867
2866
|
if (typeof Object["setPrototypeOf"] !== "undefined") {
|
|
@@ -2874,12 +2873,11 @@ function inherit(ctor, proto) {
|
|
|
2874
2873
|
ctor["prototype"] = proto;
|
|
2875
2874
|
}
|
|
2876
2875
|
}
|
|
2877
|
-
inherit(StubArray
|
|
2876
|
+
inherit(StubArray, Array.prototype);
|
|
2878
2877
|
// Weex freeze Array.prototype
|
|
2879
2878
|
// Make them writeable and configurable in prototype chain
|
|
2880
2879
|
// https://github.com/alibaba/weex/pull/1529
|
|
2881
2880
|
if (Object.isFrozen(Array)) {
|
|
2882
|
-
|
|
2883
2881
|
[
|
|
2884
2882
|
"constructor",
|
|
2885
2883
|
"push",
|
|
@@ -2894,7 +2892,7 @@ if (Object.isFrozen(Array)) {
|
|
|
2894
2892
|
"reverse",
|
|
2895
2893
|
"sort"
|
|
2896
2894
|
].forEach(function (key) {
|
|
2897
|
-
Object.defineProperty(StubArray
|
|
2895
|
+
Object.defineProperty(StubArray.prototype, key, {
|
|
2898
2896
|
configurable: true,
|
|
2899
2897
|
writable: true,
|
|
2900
2898
|
value: Array.prototype[key]
|
|
@@ -2907,7 +2905,7 @@ var ObservableArrayAdministration = /** @class */ (function () {
|
|
|
2907
2905
|
this.owned = owned;
|
|
2908
2906
|
this.values = [];
|
|
2909
2907
|
this.lastKnownLength = 0;
|
|
2910
|
-
this.atom = new Atom
|
|
2908
|
+
this.atom = new Atom(name || "ObservableArray@" + getNextId());
|
|
2911
2909
|
this.enhancer = function (newV, oldV) { return enhancer(newV, oldV, name + "[..]"); };
|
|
2912
2910
|
}
|
|
2913
2911
|
ObservableArrayAdministration.prototype.dehanceValue = function (value) {
|
|
@@ -2915,13 +2913,13 @@ var ObservableArrayAdministration = /** @class */ (function () {
|
|
|
2915
2913
|
return this.dehancer(value);
|
|
2916
2914
|
return value;
|
|
2917
2915
|
};
|
|
2918
|
-
ObservableArrayAdministration.prototype.dehanceValues = function (values
|
|
2919
|
-
if (this.dehancer !== undefined && values
|
|
2920
|
-
return values
|
|
2921
|
-
return values
|
|
2916
|
+
ObservableArrayAdministration.prototype.dehanceValues = function (values) {
|
|
2917
|
+
if (this.dehancer !== undefined && values.length > 0)
|
|
2918
|
+
return values.map(this.dehancer);
|
|
2919
|
+
return values;
|
|
2922
2920
|
};
|
|
2923
2921
|
ObservableArrayAdministration.prototype.intercept = function (handler) {
|
|
2924
|
-
return registerInterceptor
|
|
2922
|
+
return registerInterceptor(this, handler);
|
|
2925
2923
|
};
|
|
2926
2924
|
ObservableArrayAdministration.prototype.observe = function (listener, fireImmediately) {
|
|
2927
2925
|
if (fireImmediately === void 0) { fireImmediately = false; }
|
|
@@ -2936,7 +2934,7 @@ var ObservableArrayAdministration = /** @class */ (function () {
|
|
|
2936
2934
|
removedCount: 0
|
|
2937
2935
|
});
|
|
2938
2936
|
}
|
|
2939
|
-
return registerListener
|
|
2937
|
+
return registerListener(this, listener);
|
|
2940
2938
|
};
|
|
2941
2939
|
ObservableArrayAdministration.prototype.getArrayLength = function () {
|
|
2942
2940
|
this.atom.reportObserved();
|
|
@@ -2963,11 +2961,11 @@ var ObservableArrayAdministration = /** @class */ (function () {
|
|
|
2963
2961
|
throw new Error("[mobx] Modification exception: the internal structure of an observable array was changed. Did you use peek() to change it?");
|
|
2964
2962
|
this.lastKnownLength += delta;
|
|
2965
2963
|
if (delta > 0 && oldLength + delta + 1 > OBSERVABLE_ARRAY_BUFFER_SIZE)
|
|
2966
|
-
reserveArrayBuffer
|
|
2964
|
+
reserveArrayBuffer(oldLength + delta + 1);
|
|
2967
2965
|
};
|
|
2968
2966
|
ObservableArrayAdministration.prototype.spliceWithArray = function (index, deleteCount, newItems) {
|
|
2969
2967
|
var _this = this;
|
|
2970
|
-
checkIfStateModificationsAreAllowed
|
|
2968
|
+
checkIfStateModificationsAreAllowed(this.atom);
|
|
2971
2969
|
var length = this.values.length;
|
|
2972
2970
|
if (index === undefined)
|
|
2973
2971
|
index = 0;
|
|
@@ -2982,9 +2980,9 @@ var ObservableArrayAdministration = /** @class */ (function () {
|
|
|
2982
2980
|
else
|
|
2983
2981
|
deleteCount = Math.max(0, Math.min(deleteCount, length - index));
|
|
2984
2982
|
if (newItems === undefined)
|
|
2985
|
-
newItems = EMPTY_ARRAY
|
|
2986
|
-
if (hasInterceptors
|
|
2987
|
-
var change = interceptChange
|
|
2983
|
+
newItems = EMPTY_ARRAY;
|
|
2984
|
+
if (hasInterceptors(this)) {
|
|
2985
|
+
var change = interceptChange(this, {
|
|
2988
2986
|
object: this.array,
|
|
2989
2987
|
type: "splice",
|
|
2990
2988
|
index: index,
|
|
@@ -2992,7 +2990,7 @@ var ObservableArrayAdministration = /** @class */ (function () {
|
|
|
2992
2990
|
added: newItems
|
|
2993
2991
|
});
|
|
2994
2992
|
if (!change)
|
|
2995
|
-
return EMPTY_ARRAY
|
|
2993
|
+
return EMPTY_ARRAY;
|
|
2996
2994
|
deleteCount = change.removedCount;
|
|
2997
2995
|
newItems = change.added;
|
|
2998
2996
|
}
|
|
@@ -3019,8 +3017,8 @@ var ObservableArrayAdministration = /** @class */ (function () {
|
|
|
3019
3017
|
}
|
|
3020
3018
|
};
|
|
3021
3019
|
ObservableArrayAdministration.prototype.notifyArrayChildUpdate = function (index, newValue, oldValue) {
|
|
3022
|
-
var notifySpy = !this.owned && isSpyEnabled
|
|
3023
|
-
var notify = hasListeners
|
|
3020
|
+
var notifySpy = !this.owned && isSpyEnabled();
|
|
3021
|
+
var notify = hasListeners(this);
|
|
3024
3022
|
var change = notify || notifySpy
|
|
3025
3023
|
? {
|
|
3026
3024
|
object: this.array,
|
|
@@ -3031,16 +3029,16 @@ var ObservableArrayAdministration = /** @class */ (function () {
|
|
|
3031
3029
|
}
|
|
3032
3030
|
: null;
|
|
3033
3031
|
if (notifySpy)
|
|
3034
|
-
spyReportStart
|
|
3032
|
+
spyReportStart(__assign({}, change, { name: this.atom.name }));
|
|
3035
3033
|
this.atom.reportChanged();
|
|
3036
3034
|
if (notify)
|
|
3037
|
-
notifyListeners
|
|
3035
|
+
notifyListeners(this, change);
|
|
3038
3036
|
if (notifySpy)
|
|
3039
|
-
spyReportEnd
|
|
3037
|
+
spyReportEnd();
|
|
3040
3038
|
};
|
|
3041
3039
|
ObservableArrayAdministration.prototype.notifyArraySplice = function (index, added, removed) {
|
|
3042
|
-
var notifySpy = !this.owned && isSpyEnabled
|
|
3043
|
-
var notify = hasListeners
|
|
3040
|
+
var notifySpy = !this.owned && isSpyEnabled();
|
|
3041
|
+
var notify = hasListeners(this);
|
|
3044
3042
|
var change = notify || notifySpy
|
|
3045
3043
|
? {
|
|
3046
3044
|
object: this.array,
|
|
@@ -3053,28 +3051,28 @@ var ObservableArrayAdministration = /** @class */ (function () {
|
|
|
3053
3051
|
}
|
|
3054
3052
|
: null;
|
|
3055
3053
|
if (notifySpy)
|
|
3056
|
-
spyReportStart
|
|
3054
|
+
spyReportStart(__assign({}, change, { name: this.atom.name }));
|
|
3057
3055
|
this.atom.reportChanged();
|
|
3058
3056
|
// conform: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe
|
|
3059
3057
|
if (notify)
|
|
3060
|
-
notifyListeners
|
|
3058
|
+
notifyListeners(this, change);
|
|
3061
3059
|
if (notifySpy)
|
|
3062
|
-
spyReportEnd
|
|
3060
|
+
spyReportEnd();
|
|
3063
3061
|
};
|
|
3064
3062
|
return ObservableArrayAdministration;
|
|
3065
3063
|
}());
|
|
3066
|
-
var ObservableArray
|
|
3067
|
-
__extends(ObservableArray
|
|
3068
|
-
function ObservableArray
|
|
3069
|
-
if (name === void 0) { name = "ObservableArray@" + getNextId
|
|
3064
|
+
var ObservableArray = /** @class */ (function (_super) {
|
|
3065
|
+
__extends(ObservableArray, _super);
|
|
3066
|
+
function ObservableArray(initialValues, enhancer, name, owned) {
|
|
3067
|
+
if (name === void 0) { name = "ObservableArray@" + getNextId(); }
|
|
3070
3068
|
if (owned === void 0) { owned = false; }
|
|
3071
3069
|
var _this = _super.call(this) || this;
|
|
3072
3070
|
var adm = new ObservableArrayAdministration(name, enhancer, _this, owned);
|
|
3073
|
-
addHiddenFinalProp
|
|
3071
|
+
addHiddenFinalProp(_this, "$mobx", adm);
|
|
3074
3072
|
if (initialValues && initialValues.length) {
|
|
3075
|
-
var prev = allowStateChangesStart
|
|
3073
|
+
var prev = allowStateChangesStart(true);
|
|
3076
3074
|
_this.spliceWithArray(0, 0, initialValues);
|
|
3077
|
-
allowStateChangesEnd
|
|
3075
|
+
allowStateChangesEnd(prev);
|
|
3078
3076
|
}
|
|
3079
3077
|
if (safariPrototypeSetterInheritanceBug) {
|
|
3080
3078
|
// Seems that Safari won't use numeric prototype setter untill any * numeric property is
|
|
@@ -3083,55 +3081,55 @@ var ObservableArray$$1 = /** @class */ (function (_super) {
|
|
|
3083
3081
|
}
|
|
3084
3082
|
return _this;
|
|
3085
3083
|
}
|
|
3086
|
-
ObservableArray
|
|
3084
|
+
ObservableArray.prototype.intercept = function (handler) {
|
|
3087
3085
|
return this.$mobx.intercept(handler);
|
|
3088
3086
|
};
|
|
3089
|
-
ObservableArray
|
|
3087
|
+
ObservableArray.prototype.observe = function (listener, fireImmediately) {
|
|
3090
3088
|
if (fireImmediately === void 0) { fireImmediately = false; }
|
|
3091
3089
|
return this.$mobx.observe(listener, fireImmediately);
|
|
3092
3090
|
};
|
|
3093
|
-
ObservableArray
|
|
3091
|
+
ObservableArray.prototype.clear = function () {
|
|
3094
3092
|
return this.splice(0);
|
|
3095
3093
|
};
|
|
3096
|
-
ObservableArray
|
|
3094
|
+
ObservableArray.prototype.concat = function () {
|
|
3097
3095
|
var arrays = [];
|
|
3098
3096
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3099
3097
|
arrays[_i] = arguments[_i];
|
|
3100
3098
|
}
|
|
3101
3099
|
this.$mobx.atom.reportObserved();
|
|
3102
|
-
return Array.prototype.concat.apply(this.peek(), arrays.map(function (a) { return (isObservableArray
|
|
3100
|
+
return Array.prototype.concat.apply(this.peek(), arrays.map(function (a) { return (isObservableArray(a) ? a.peek() : a); }));
|
|
3103
3101
|
};
|
|
3104
|
-
ObservableArray
|
|
3102
|
+
ObservableArray.prototype.replace = function (newItems) {
|
|
3105
3103
|
return this.$mobx.spliceWithArray(0, this.$mobx.values.length, newItems);
|
|
3106
3104
|
};
|
|
3107
3105
|
/**
|
|
3108
3106
|
* Converts this array back to a (shallow) javascript structure.
|
|
3109
3107
|
* For a deep clone use mobx.toJS
|
|
3110
3108
|
*/
|
|
3111
|
-
ObservableArray
|
|
3109
|
+
ObservableArray.prototype.toJS = function () {
|
|
3112
3110
|
return this.slice();
|
|
3113
3111
|
};
|
|
3114
|
-
ObservableArray
|
|
3112
|
+
ObservableArray.prototype.toJSON = function () {
|
|
3115
3113
|
// Used by JSON.stringify
|
|
3116
3114
|
return this.toJS();
|
|
3117
3115
|
};
|
|
3118
|
-
ObservableArray
|
|
3116
|
+
ObservableArray.prototype.peek = function () {
|
|
3119
3117
|
this.$mobx.atom.reportObserved();
|
|
3120
3118
|
return this.$mobx.dehanceValues(this.$mobx.values);
|
|
3121
3119
|
};
|
|
3122
3120
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
|
|
3123
|
-
ObservableArray
|
|
3121
|
+
ObservableArray.prototype.find = function (predicate, thisArg, fromIndex) {
|
|
3124
3122
|
if (fromIndex === void 0) { fromIndex = 0; }
|
|
3125
3123
|
if (arguments.length === 3)
|
|
3126
|
-
deprecated
|
|
3124
|
+
deprecated("The array.find fromIndex argument to find will not be supported anymore in the next major");
|
|
3127
3125
|
var idx = this.findIndex.apply(this, arguments);
|
|
3128
3126
|
return idx === -1 ? undefined : this.get(idx);
|
|
3129
3127
|
};
|
|
3130
3128
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex
|
|
3131
|
-
ObservableArray
|
|
3129
|
+
ObservableArray.prototype.findIndex = function (predicate, thisArg, fromIndex) {
|
|
3132
3130
|
if (fromIndex === void 0) { fromIndex = 0; }
|
|
3133
3131
|
if (arguments.length === 3)
|
|
3134
|
-
deprecated
|
|
3132
|
+
deprecated("The array.findIndex fromIndex argument to find will not be supported anymore in the next major");
|
|
3135
3133
|
var items = this.peek(), l = items.length;
|
|
3136
3134
|
for (var i = fromIndex; i < l; i++)
|
|
3137
3135
|
if (predicate.call(thisArg, items[i], i, this))
|
|
@@ -3144,7 +3142,7 @@ var ObservableArray$$1 = /** @class */ (function (_super) {
|
|
|
3144
3142
|
* Because the have side effects, they should not be used in computed function,
|
|
3145
3143
|
* and for that reason the do not call dependencyState.notifyObserved
|
|
3146
3144
|
*/
|
|
3147
|
-
ObservableArray
|
|
3145
|
+
ObservableArray.prototype.splice = function (index, deleteCount) {
|
|
3148
3146
|
var newItems = [];
|
|
3149
3147
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
3150
3148
|
newItems[_i - 2] = arguments[_i];
|
|
@@ -3159,10 +3157,10 @@ var ObservableArray$$1 = /** @class */ (function (_super) {
|
|
|
3159
3157
|
}
|
|
3160
3158
|
return this.$mobx.spliceWithArray(index, deleteCount, newItems);
|
|
3161
3159
|
};
|
|
3162
|
-
ObservableArray
|
|
3160
|
+
ObservableArray.prototype.spliceWithArray = function (index, deleteCount, newItems) {
|
|
3163
3161
|
return this.$mobx.spliceWithArray(index, deleteCount, newItems);
|
|
3164
3162
|
};
|
|
3165
|
-
ObservableArray
|
|
3163
|
+
ObservableArray.prototype.push = function () {
|
|
3166
3164
|
var items = [];
|
|
3167
3165
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3168
3166
|
items[_i] = arguments[_i];
|
|
@@ -3171,13 +3169,13 @@ var ObservableArray$$1 = /** @class */ (function (_super) {
|
|
|
3171
3169
|
adm.spliceWithArray(adm.values.length, 0, items);
|
|
3172
3170
|
return adm.values.length;
|
|
3173
3171
|
};
|
|
3174
|
-
ObservableArray
|
|
3172
|
+
ObservableArray.prototype.pop = function () {
|
|
3175
3173
|
return this.splice(Math.max(this.$mobx.values.length - 1, 0), 1)[0];
|
|
3176
3174
|
};
|
|
3177
|
-
ObservableArray
|
|
3175
|
+
ObservableArray.prototype.shift = function () {
|
|
3178
3176
|
return this.splice(0, 1)[0];
|
|
3179
3177
|
};
|
|
3180
|
-
ObservableArray
|
|
3178
|
+
ObservableArray.prototype.unshift = function () {
|
|
3181
3179
|
var items = [];
|
|
3182
3180
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3183
3181
|
items[_i] = arguments[_i];
|
|
@@ -3186,20 +3184,20 @@ var ObservableArray$$1 = /** @class */ (function (_super) {
|
|
|
3186
3184
|
adm.spliceWithArray(0, 0, items);
|
|
3187
3185
|
return adm.values.length;
|
|
3188
3186
|
};
|
|
3189
|
-
ObservableArray
|
|
3187
|
+
ObservableArray.prototype.reverse = function () {
|
|
3190
3188
|
// reverse by default mutates in place before returning the result
|
|
3191
3189
|
// which makes it both a 'derivation' and a 'mutation'.
|
|
3192
3190
|
// so we deviate from the default and just make it an dervitation
|
|
3193
3191
|
var clone = this.slice();
|
|
3194
3192
|
return clone.reverse.apply(clone, arguments);
|
|
3195
3193
|
};
|
|
3196
|
-
ObservableArray
|
|
3194
|
+
ObservableArray.prototype.sort = function (compareFn) {
|
|
3197
3195
|
// sort by default mutates in place before returning the result
|
|
3198
3196
|
// which goes against all good practices. Let's not change the array in place!
|
|
3199
3197
|
var clone = this.slice();
|
|
3200
3198
|
return clone.sort.apply(clone, arguments);
|
|
3201
3199
|
};
|
|
3202
|
-
ObservableArray
|
|
3200
|
+
ObservableArray.prototype.remove = function (value) {
|
|
3203
3201
|
var idx = this.$mobx.dehanceValues(this.$mobx.values).indexOf(value);
|
|
3204
3202
|
if (idx > -1) {
|
|
3205
3203
|
this.splice(idx, 1);
|
|
@@ -3207,8 +3205,8 @@ var ObservableArray$$1 = /** @class */ (function (_super) {
|
|
|
3207
3205
|
}
|
|
3208
3206
|
return false;
|
|
3209
3207
|
};
|
|
3210
|
-
ObservableArray
|
|
3211
|
-
deprecated
|
|
3208
|
+
ObservableArray.prototype.move = function (fromIndex, toIndex) {
|
|
3209
|
+
deprecated("observableArray.move is deprecated, use .slice() & .replace() instead");
|
|
3212
3210
|
function checkIndex(index) {
|
|
3213
3211
|
if (index < 0) {
|
|
3214
3212
|
throw new Error("[mobx.array] Index out of bounds: " + index + " is negative");
|
|
@@ -3239,7 +3237,7 @@ var ObservableArray$$1 = /** @class */ (function (_super) {
|
|
|
3239
3237
|
this.replace(newItems);
|
|
3240
3238
|
};
|
|
3241
3239
|
// See #734, in case property accessors are unreliable...
|
|
3242
|
-
ObservableArray
|
|
3240
|
+
ObservableArray.prototype.get = function (index) {
|
|
3243
3241
|
var impl = this.$mobx;
|
|
3244
3242
|
if (impl) {
|
|
3245
3243
|
if (index < impl.values.length) {
|
|
@@ -3251,15 +3249,15 @@ var ObservableArray$$1 = /** @class */ (function (_super) {
|
|
|
3251
3249
|
return undefined;
|
|
3252
3250
|
};
|
|
3253
3251
|
// See #734, in case property accessors are unreliable...
|
|
3254
|
-
ObservableArray
|
|
3252
|
+
ObservableArray.prototype.set = function (index, newValue) {
|
|
3255
3253
|
var adm = this.$mobx;
|
|
3256
|
-
var values
|
|
3257
|
-
if (index < values
|
|
3254
|
+
var values = adm.values;
|
|
3255
|
+
if (index < values.length) {
|
|
3258
3256
|
// update at index in range
|
|
3259
|
-
checkIfStateModificationsAreAllowed
|
|
3260
|
-
var oldValue = values
|
|
3261
|
-
if (hasInterceptors
|
|
3262
|
-
var change = interceptChange
|
|
3257
|
+
checkIfStateModificationsAreAllowed(adm.atom);
|
|
3258
|
+
var oldValue = values[index];
|
|
3259
|
+
if (hasInterceptors(adm)) {
|
|
3260
|
+
var change = interceptChange(adm, {
|
|
3263
3261
|
type: "update",
|
|
3264
3262
|
object: this,
|
|
3265
3263
|
index: index,
|
|
@@ -3272,27 +3270,26 @@ var ObservableArray$$1 = /** @class */ (function (_super) {
|
|
|
3272
3270
|
newValue = adm.enhancer(newValue, oldValue);
|
|
3273
3271
|
var changed = newValue !== oldValue;
|
|
3274
3272
|
if (changed) {
|
|
3275
|
-
values
|
|
3273
|
+
values[index] = newValue;
|
|
3276
3274
|
adm.notifyArrayChildUpdate(index, newValue, oldValue);
|
|
3277
3275
|
}
|
|
3278
3276
|
}
|
|
3279
|
-
else if (index === values
|
|
3277
|
+
else if (index === values.length) {
|
|
3280
3278
|
// add a new item
|
|
3281
3279
|
adm.spliceWithArray(index, 0, [newValue]);
|
|
3282
3280
|
}
|
|
3283
3281
|
else {
|
|
3284
3282
|
// out of bounds
|
|
3285
|
-
throw new Error("[mobx.array] Index out of bounds, " + index + " is larger than " + values
|
|
3283
|
+
throw new Error("[mobx.array] Index out of bounds, " + index + " is larger than " + values.length);
|
|
3286
3284
|
}
|
|
3287
3285
|
};
|
|
3288
|
-
return ObservableArray
|
|
3289
|
-
}(StubArray
|
|
3290
|
-
declareIterator
|
|
3291
|
-
|
|
3286
|
+
return ObservableArray;
|
|
3287
|
+
}(StubArray));
|
|
3288
|
+
declareIterator(ObservableArray.prototype, function () {
|
|
3292
3289
|
this.$mobx.atom.reportObserved();
|
|
3293
3290
|
var self = this;
|
|
3294
3291
|
var nextIndex = 0;
|
|
3295
|
-
return makeIterable
|
|
3292
|
+
return makeIterable({
|
|
3296
3293
|
next: function () {
|
|
3297
3294
|
return nextIndex < self.length
|
|
3298
3295
|
? { value: self[nextIndex++], done: false }
|
|
@@ -3300,7 +3297,7 @@ declareIterator$$1(ObservableArray$$1.prototype, function () {
|
|
|
3300
3297
|
}
|
|
3301
3298
|
});
|
|
3302
3299
|
});
|
|
3303
|
-
Object.defineProperty(ObservableArray
|
|
3300
|
+
Object.defineProperty(ObservableArray.prototype, "length", {
|
|
3304
3301
|
enumerable: false,
|
|
3305
3302
|
configurable: true,
|
|
3306
3303
|
get: function () {
|
|
@@ -3310,7 +3307,7 @@ Object.defineProperty(ObservableArray$$1.prototype, "length", {
|
|
|
3310
3307
|
this.$mobx.setArrayLength(newLength);
|
|
3311
3308
|
}
|
|
3312
3309
|
});
|
|
3313
|
-
addHiddenProp
|
|
3310
|
+
addHiddenProp(ObservableArray.prototype, toStringTagSymbol(), "Array");
|
|
3314
3311
|
[
|
|
3315
3312
|
"every",
|
|
3316
3313
|
"filter",
|
|
@@ -3327,15 +3324,15 @@ addHiddenProp$$1(ObservableArray$$1.prototype, toStringTagSymbol$$1(), "Array");
|
|
|
3327
3324
|
"toLocaleString"
|
|
3328
3325
|
].forEach(function (funcName) {
|
|
3329
3326
|
var baseFunc = Array.prototype[funcName];
|
|
3330
|
-
invariant
|
|
3331
|
-
addHiddenProp
|
|
3327
|
+
invariant(typeof baseFunc === "function", "Base function not defined on Array prototype: '" + funcName + "'");
|
|
3328
|
+
addHiddenProp(ObservableArray.prototype, funcName, function () {
|
|
3332
3329
|
return baseFunc.apply(this.peek(), arguments);
|
|
3333
3330
|
});
|
|
3334
3331
|
});
|
|
3335
3332
|
/**
|
|
3336
3333
|
* We don't want those to show up in `for (const key in ar)` ...
|
|
3337
3334
|
*/
|
|
3338
|
-
makeNonEnumerable
|
|
3335
|
+
makeNonEnumerable(ObservableArray.prototype, [
|
|
3339
3336
|
"constructor",
|
|
3340
3337
|
"intercept",
|
|
3341
3338
|
"observe",
|
|
@@ -3377,28 +3374,28 @@ function createArrayEntryDescriptor(index) {
|
|
|
3377
3374
|
};
|
|
3378
3375
|
}
|
|
3379
3376
|
function createArrayBufferItem(index) {
|
|
3380
|
-
Object.defineProperty(ObservableArray
|
|
3377
|
+
Object.defineProperty(ObservableArray.prototype, "" + index, createArrayEntryDescriptor(index));
|
|
3381
3378
|
}
|
|
3382
|
-
function reserveArrayBuffer
|
|
3379
|
+
function reserveArrayBuffer(max) {
|
|
3383
3380
|
for (var index = OBSERVABLE_ARRAY_BUFFER_SIZE; index < max; index++)
|
|
3384
3381
|
createArrayBufferItem(index);
|
|
3385
3382
|
OBSERVABLE_ARRAY_BUFFER_SIZE = max;
|
|
3386
3383
|
}
|
|
3387
|
-
reserveArrayBuffer
|
|
3388
|
-
var isObservableArrayAdministration = createInstanceofPredicate
|
|
3389
|
-
function isObservableArray
|
|
3390
|
-
return isObject
|
|
3384
|
+
reserveArrayBuffer(1000);
|
|
3385
|
+
var isObservableArrayAdministration = createInstanceofPredicate("ObservableArrayAdministration", ObservableArrayAdministration);
|
|
3386
|
+
function isObservableArray(thing) {
|
|
3387
|
+
return isObject(thing) && isObservableArrayAdministration(thing.$mobx);
|
|
3391
3388
|
}
|
|
3392
3389
|
|
|
3393
3390
|
var ObservableMapMarker = {};
|
|
3394
|
-
var ObservableMap
|
|
3395
|
-
function ObservableMap
|
|
3396
|
-
if (enhancer === void 0) { enhancer = deepEnhancer
|
|
3397
|
-
if (name === void 0) { name = "ObservableMap@" + getNextId
|
|
3391
|
+
var ObservableMap = /** @class */ (function () {
|
|
3392
|
+
function ObservableMap(initialData, enhancer, name) {
|
|
3393
|
+
if (enhancer === void 0) { enhancer = deepEnhancer; }
|
|
3394
|
+
if (name === void 0) { name = "ObservableMap@" + getNextId(); }
|
|
3398
3395
|
this.enhancer = enhancer;
|
|
3399
3396
|
this.name = name;
|
|
3400
3397
|
this.$mobx = ObservableMapMarker;
|
|
3401
|
-
this._keys = new ObservableArray
|
|
3398
|
+
this._keys = (new ObservableArray(undefined, referenceEnhancer, this.name + ".keys()", true));
|
|
3402
3399
|
if (typeof Map !== "function") {
|
|
3403
3400
|
throw new Error("mobx.map requires Map polyfill for the current browser. Check babel-polyfill or core-js/es6/map.js");
|
|
3404
3401
|
}
|
|
@@ -3406,18 +3403,26 @@ var ObservableMap$$1 = /** @class */ (function () {
|
|
|
3406
3403
|
this._hasMap = new Map();
|
|
3407
3404
|
this.merge(initialData);
|
|
3408
3405
|
}
|
|
3409
|
-
ObservableMap
|
|
3406
|
+
ObservableMap.prototype._has = function (key) {
|
|
3410
3407
|
return this._data.has(key);
|
|
3411
3408
|
};
|
|
3412
|
-
ObservableMap
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3409
|
+
ObservableMap.prototype.has = function (key) {
|
|
3410
|
+
var _this = this;
|
|
3411
|
+
if (!globalState.trackingDerivation)
|
|
3412
|
+
return this._has(key);
|
|
3413
|
+
var entry = this._hasMap.get(key);
|
|
3414
|
+
if (!entry) {
|
|
3415
|
+
// todo: replace with atom (breaking change)
|
|
3416
|
+
var newEntry = (entry = new ObservableValue(this._has(key), referenceEnhancer, this.name + "." + stringifyKey(key) + "?", false));
|
|
3417
|
+
this._hasMap.set(key, newEntry);
|
|
3418
|
+
onBecomeUnobserved(newEntry, function () { return _this._hasMap.delete(key); });
|
|
3419
|
+
}
|
|
3420
|
+
return entry.get();
|
|
3416
3421
|
};
|
|
3417
|
-
ObservableMap
|
|
3422
|
+
ObservableMap.prototype.set = function (key, value) {
|
|
3418
3423
|
var hasKey = this._has(key);
|
|
3419
|
-
if (hasInterceptors
|
|
3420
|
-
var change = interceptChange
|
|
3424
|
+
if (hasInterceptors(this)) {
|
|
3425
|
+
var change = interceptChange(this, {
|
|
3421
3426
|
type: hasKey ? "update" : "add",
|
|
3422
3427
|
object: this,
|
|
3423
3428
|
newValue: value,
|
|
@@ -3435,10 +3440,10 @@ var ObservableMap$$1 = /** @class */ (function () {
|
|
|
3435
3440
|
}
|
|
3436
3441
|
return this;
|
|
3437
3442
|
};
|
|
3438
|
-
ObservableMap
|
|
3443
|
+
ObservableMap.prototype.delete = function (key) {
|
|
3439
3444
|
var _this = this;
|
|
3440
|
-
if (hasInterceptors
|
|
3441
|
-
var change = interceptChange
|
|
3445
|
+
if (hasInterceptors(this)) {
|
|
3446
|
+
var change = interceptChange(this, {
|
|
3442
3447
|
type: "delete",
|
|
3443
3448
|
object: this,
|
|
3444
3449
|
name: key
|
|
@@ -3447,8 +3452,8 @@ var ObservableMap$$1 = /** @class */ (function () {
|
|
|
3447
3452
|
return false;
|
|
3448
3453
|
}
|
|
3449
3454
|
if (this._has(key)) {
|
|
3450
|
-
var notifySpy = isSpyEnabled
|
|
3451
|
-
var notify = hasListeners
|
|
3455
|
+
var notifySpy = isSpyEnabled();
|
|
3456
|
+
var notify = hasListeners(this);
|
|
3452
3457
|
var change = notify || notifySpy
|
|
3453
3458
|
? {
|
|
3454
3459
|
type: "delete",
|
|
@@ -3458,69 +3463,63 @@ var ObservableMap$$1 = /** @class */ (function () {
|
|
|
3458
3463
|
}
|
|
3459
3464
|
: null;
|
|
3460
3465
|
if (notifySpy)
|
|
3461
|
-
spyReportStart
|
|
3462
|
-
transaction
|
|
3466
|
+
spyReportStart(__assign({}, change, { name: this.name, key: key }));
|
|
3467
|
+
transaction(function () {
|
|
3463
3468
|
_this._keys.remove(key);
|
|
3464
3469
|
_this._updateHasMapEntry(key, false);
|
|
3465
|
-
var observable
|
|
3466
|
-
observable
|
|
3470
|
+
var observable = _this._data.get(key);
|
|
3471
|
+
observable.setNewValue(undefined);
|
|
3467
3472
|
_this._data.delete(key);
|
|
3468
3473
|
});
|
|
3469
3474
|
if (notify)
|
|
3470
|
-
notifyListeners
|
|
3475
|
+
notifyListeners(this, change);
|
|
3471
3476
|
if (notifySpy)
|
|
3472
|
-
spyReportEnd
|
|
3477
|
+
spyReportEnd();
|
|
3473
3478
|
return true;
|
|
3474
3479
|
}
|
|
3475
3480
|
return false;
|
|
3476
3481
|
};
|
|
3477
|
-
ObservableMap
|
|
3478
|
-
// optimization; don't fill the hasMap if we are not observing, or remove entry if there are no observers anymore
|
|
3482
|
+
ObservableMap.prototype._updateHasMapEntry = function (key, value) {
|
|
3479
3483
|
var entry = this._hasMap.get(key);
|
|
3480
3484
|
if (entry) {
|
|
3481
3485
|
entry.setNewValue(value);
|
|
3482
3486
|
}
|
|
3483
|
-
else {
|
|
3484
|
-
entry = new ObservableValue$$1(value, referenceEnhancer$$1, this.name + "." + stringifyKey(key) + "?", false);
|
|
3485
|
-
this._hasMap.set(key, entry);
|
|
3486
|
-
}
|
|
3487
|
-
return entry;
|
|
3488
3487
|
};
|
|
3489
|
-
ObservableMap
|
|
3490
|
-
var observable
|
|
3491
|
-
newValue = observable
|
|
3492
|
-
if (newValue !== globalState
|
|
3493
|
-
var notifySpy = isSpyEnabled
|
|
3494
|
-
var notify = hasListeners
|
|
3488
|
+
ObservableMap.prototype._updateValue = function (key, newValue) {
|
|
3489
|
+
var observable = this._data.get(key);
|
|
3490
|
+
newValue = observable.prepareNewValue(newValue);
|
|
3491
|
+
if (newValue !== globalState.UNCHANGED) {
|
|
3492
|
+
var notifySpy = isSpyEnabled();
|
|
3493
|
+
var notify = hasListeners(this);
|
|
3495
3494
|
var change = notify || notifySpy
|
|
3496
3495
|
? {
|
|
3497
3496
|
type: "update",
|
|
3498
3497
|
object: this,
|
|
3499
|
-
oldValue: observable
|
|
3498
|
+
oldValue: observable.value,
|
|
3500
3499
|
name: key,
|
|
3501
3500
|
newValue: newValue
|
|
3502
3501
|
}
|
|
3503
3502
|
: null;
|
|
3504
3503
|
if (notifySpy)
|
|
3505
|
-
spyReportStart
|
|
3506
|
-
observable
|
|
3504
|
+
spyReportStart(__assign({}, change, { name: this.name, key: key }));
|
|
3505
|
+
observable.setNewValue(newValue);
|
|
3507
3506
|
if (notify)
|
|
3508
|
-
notifyListeners
|
|
3507
|
+
notifyListeners(this, change);
|
|
3509
3508
|
if (notifySpy)
|
|
3510
|
-
spyReportEnd
|
|
3509
|
+
spyReportEnd();
|
|
3511
3510
|
}
|
|
3512
3511
|
};
|
|
3513
|
-
ObservableMap
|
|
3512
|
+
ObservableMap.prototype._addValue = function (key, newValue) {
|
|
3514
3513
|
var _this = this;
|
|
3515
|
-
transaction
|
|
3516
|
-
var observable
|
|
3517
|
-
_this._data.set(key, observable
|
|
3518
|
-
newValue = observable
|
|
3514
|
+
transaction(function () {
|
|
3515
|
+
var observable = new ObservableValue(newValue, _this.enhancer, _this.name + "." + stringifyKey(key), false);
|
|
3516
|
+
_this._data.set(key, observable);
|
|
3517
|
+
newValue = observable.value; // value might have been changed
|
|
3519
3518
|
_this._updateHasMapEntry(key, true);
|
|
3520
3519
|
_this._keys.push(key);
|
|
3521
3520
|
});
|
|
3522
|
-
var notifySpy = isSpyEnabled
|
|
3523
|
-
var notify = hasListeners
|
|
3521
|
+
var notifySpy = isSpyEnabled();
|
|
3522
|
+
var notify = hasListeners(this);
|
|
3524
3523
|
var change = notify || notifySpy
|
|
3525
3524
|
? {
|
|
3526
3525
|
type: "add",
|
|
@@ -3530,30 +3529,30 @@ var ObservableMap$$1 = /** @class */ (function () {
|
|
|
3530
3529
|
}
|
|
3531
3530
|
: null;
|
|
3532
3531
|
if (notifySpy)
|
|
3533
|
-
spyReportStart
|
|
3532
|
+
spyReportStart(__assign({}, change, { name: this.name, key: key }));
|
|
3534
3533
|
if (notify)
|
|
3535
|
-
notifyListeners
|
|
3534
|
+
notifyListeners(this, change);
|
|
3536
3535
|
if (notifySpy)
|
|
3537
|
-
spyReportEnd
|
|
3536
|
+
spyReportEnd();
|
|
3538
3537
|
};
|
|
3539
|
-
ObservableMap
|
|
3538
|
+
ObservableMap.prototype.get = function (key) {
|
|
3540
3539
|
if (this.has(key))
|
|
3541
3540
|
return this.dehanceValue(this._data.get(key).get());
|
|
3542
3541
|
return this.dehanceValue(undefined);
|
|
3543
3542
|
};
|
|
3544
|
-
ObservableMap
|
|
3543
|
+
ObservableMap.prototype.dehanceValue = function (value) {
|
|
3545
3544
|
if (this.dehancer !== undefined) {
|
|
3546
3545
|
return this.dehancer(value);
|
|
3547
3546
|
}
|
|
3548
3547
|
return value;
|
|
3549
3548
|
};
|
|
3550
|
-
ObservableMap
|
|
3551
|
-
return this._keys[iteratorSymbol
|
|
3549
|
+
ObservableMap.prototype.keys = function () {
|
|
3550
|
+
return this._keys[iteratorSymbol()]();
|
|
3552
3551
|
};
|
|
3553
|
-
ObservableMap
|
|
3552
|
+
ObservableMap.prototype.values = function () {
|
|
3554
3553
|
var self = this;
|
|
3555
3554
|
var nextIndex = 0;
|
|
3556
|
-
return makeIterable
|
|
3555
|
+
return makeIterable({
|
|
3557
3556
|
next: function () {
|
|
3558
3557
|
return nextIndex < self._keys.length
|
|
3559
3558
|
? { value: self.get(self._keys[nextIndex++]), done: false }
|
|
@@ -3561,10 +3560,10 @@ var ObservableMap$$1 = /** @class */ (function () {
|
|
|
3561
3560
|
}
|
|
3562
3561
|
});
|
|
3563
3562
|
};
|
|
3564
|
-
ObservableMap
|
|
3563
|
+
ObservableMap.prototype.entries = function () {
|
|
3565
3564
|
var self = this;
|
|
3566
3565
|
var nextIndex = 0;
|
|
3567
|
-
return makeIterable
|
|
3566
|
+
return makeIterable({
|
|
3568
3567
|
next: function () {
|
|
3569
3568
|
if (nextIndex < self._keys.length) {
|
|
3570
3569
|
var key = self._keys[nextIndex++];
|
|
@@ -3577,58 +3576,58 @@ var ObservableMap$$1 = /** @class */ (function () {
|
|
|
3577
3576
|
}
|
|
3578
3577
|
});
|
|
3579
3578
|
};
|
|
3580
|
-
ObservableMap
|
|
3579
|
+
ObservableMap.prototype.forEach = function (callback, thisArg) {
|
|
3581
3580
|
var _this = this;
|
|
3582
3581
|
this._keys.forEach(function (key) { return callback.call(thisArg, _this.get(key), key, _this); });
|
|
3583
3582
|
};
|
|
3584
3583
|
/** Merge another object into this object, returns this. */
|
|
3585
|
-
ObservableMap
|
|
3584
|
+
ObservableMap.prototype.merge = function (other) {
|
|
3586
3585
|
var _this = this;
|
|
3587
|
-
if (isObservableMap
|
|
3586
|
+
if (isObservableMap(other)) {
|
|
3588
3587
|
other = other.toJS();
|
|
3589
3588
|
}
|
|
3590
|
-
transaction
|
|
3591
|
-
if (isPlainObject
|
|
3589
|
+
transaction(function () {
|
|
3590
|
+
if (isPlainObject(other))
|
|
3592
3591
|
Object.keys(other).forEach(function (key) { return _this.set(key, other[key]); });
|
|
3593
3592
|
else if (Array.isArray(other))
|
|
3594
3593
|
other.forEach(function (_a) {
|
|
3595
3594
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
3596
3595
|
return _this.set(key, value);
|
|
3597
3596
|
});
|
|
3598
|
-
else if (isES6Map
|
|
3597
|
+
else if (isES6Map(other)) {
|
|
3599
3598
|
if (other.constructor !== Map)
|
|
3600
|
-
fail
|
|
3599
|
+
fail("Cannot initialize from classes that inherit from Map: " + other.constructor.name); // prettier-ignore
|
|
3601
3600
|
else
|
|
3602
3601
|
other.forEach(function (value, key) { return _this.set(key, value); });
|
|
3603
3602
|
}
|
|
3604
3603
|
else if (other !== null && other !== undefined)
|
|
3605
|
-
fail
|
|
3604
|
+
fail("Cannot initialize map from " + other);
|
|
3606
3605
|
});
|
|
3607
3606
|
return this;
|
|
3608
3607
|
};
|
|
3609
|
-
ObservableMap
|
|
3608
|
+
ObservableMap.prototype.clear = function () {
|
|
3610
3609
|
var _this = this;
|
|
3611
|
-
transaction
|
|
3612
|
-
untracked
|
|
3610
|
+
transaction(function () {
|
|
3611
|
+
untracked(function () {
|
|
3613
3612
|
_this._keys.slice().forEach(function (key) { return _this.delete(key); });
|
|
3614
3613
|
});
|
|
3615
3614
|
});
|
|
3616
3615
|
};
|
|
3617
|
-
ObservableMap
|
|
3616
|
+
ObservableMap.prototype.replace = function (values) {
|
|
3618
3617
|
var _this = this;
|
|
3619
|
-
transaction
|
|
3618
|
+
transaction(function () {
|
|
3620
3619
|
// grab all the keys that are present in the new map but not present in the current map
|
|
3621
3620
|
// and delete them from the map, then merge the new map
|
|
3622
3621
|
// this will cause reactions only on changed values
|
|
3623
|
-
var newKeys = getMapLikeKeys
|
|
3622
|
+
var newKeys = getMapLikeKeys(values);
|
|
3624
3623
|
var oldKeys = _this._keys;
|
|
3625
3624
|
var missingKeys = oldKeys.filter(function (k) { return newKeys.indexOf(k) === -1; });
|
|
3626
3625
|
missingKeys.forEach(function (k) { return _this.delete(k); });
|
|
3627
|
-
_this.merge(values
|
|
3626
|
+
_this.merge(values);
|
|
3628
3627
|
});
|
|
3629
3628
|
return this;
|
|
3630
3629
|
};
|
|
3631
|
-
Object.defineProperty(ObservableMap
|
|
3630
|
+
Object.defineProperty(ObservableMap.prototype, "size", {
|
|
3632
3631
|
get: function () {
|
|
3633
3632
|
return this._keys.length;
|
|
3634
3633
|
},
|
|
@@ -3640,7 +3639,7 @@ var ObservableMap$$1 = /** @class */ (function () {
|
|
|
3640
3639
|
* Note that all the keys being stringified.
|
|
3641
3640
|
* If there are duplicating keys after converting them to strings, behaviour is undetermined.
|
|
3642
3641
|
*/
|
|
3643
|
-
ObservableMap
|
|
3642
|
+
ObservableMap.prototype.toPOJO = function () {
|
|
3644
3643
|
var _this = this;
|
|
3645
3644
|
var res = {};
|
|
3646
3645
|
this._keys.forEach(function (key) { return (res[typeof key === "symbol" ? key : stringifyKey(key)] = _this.get(key)); });
|
|
@@ -3650,17 +3649,17 @@ var ObservableMap$$1 = /** @class */ (function () {
|
|
|
3650
3649
|
* Returns a shallow non observable object clone of this map.
|
|
3651
3650
|
* Note that the values migth still be observable. For a deep clone use mobx.toJS.
|
|
3652
3651
|
*/
|
|
3653
|
-
ObservableMap
|
|
3652
|
+
ObservableMap.prototype.toJS = function () {
|
|
3654
3653
|
var _this = this;
|
|
3655
3654
|
var res = new Map();
|
|
3656
3655
|
this._keys.forEach(function (key) { return res.set(key, _this.get(key)); });
|
|
3657
3656
|
return res;
|
|
3658
3657
|
};
|
|
3659
|
-
ObservableMap
|
|
3658
|
+
ObservableMap.prototype.toJSON = function () {
|
|
3660
3659
|
// Used by JSON.stringify
|
|
3661
3660
|
return this.toPOJO();
|
|
3662
3661
|
};
|
|
3663
|
-
ObservableMap
|
|
3662
|
+
ObservableMap.prototype.toString = function () {
|
|
3664
3663
|
var _this = this;
|
|
3665
3664
|
return (this.name +
|
|
3666
3665
|
"[{ " +
|
|
@@ -3672,15 +3671,15 @@ var ObservableMap$$1 = /** @class */ (function () {
|
|
|
3672
3671
|
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/observe
|
|
3673
3672
|
* for callback details
|
|
3674
3673
|
*/
|
|
3675
|
-
ObservableMap
|
|
3674
|
+
ObservableMap.prototype.observe = function (listener, fireImmediately) {
|
|
3676
3675
|
process.env.NODE_ENV !== "production" &&
|
|
3677
|
-
invariant
|
|
3678
|
-
return registerListener
|
|
3676
|
+
invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with maps.");
|
|
3677
|
+
return registerListener(this, listener);
|
|
3679
3678
|
};
|
|
3680
|
-
ObservableMap
|
|
3681
|
-
return registerInterceptor
|
|
3679
|
+
ObservableMap.prototype.intercept = function (handler) {
|
|
3680
|
+
return registerInterceptor(this, handler);
|
|
3682
3681
|
};
|
|
3683
|
-
return ObservableMap
|
|
3682
|
+
return ObservableMap;
|
|
3684
3683
|
}());
|
|
3685
3684
|
function stringifyKey(key) {
|
|
3686
3685
|
if (key && key.toString)
|
|
@@ -3688,22 +3687,22 @@ function stringifyKey(key) {
|
|
|
3688
3687
|
else
|
|
3689
3688
|
return new String(key).toString();
|
|
3690
3689
|
}
|
|
3691
|
-
declareIterator
|
|
3690
|
+
declareIterator(ObservableMap.prototype, function () {
|
|
3692
3691
|
return this.entries();
|
|
3693
3692
|
});
|
|
3694
|
-
addHiddenFinalProp
|
|
3693
|
+
addHiddenFinalProp(ObservableMap.prototype, toStringTagSymbol(), "Map");
|
|
3695
3694
|
/* 'var' fixes small-build issue */
|
|
3696
|
-
var isObservableMap
|
|
3695
|
+
var isObservableMap = createInstanceofPredicate("ObservableMap", ObservableMap);
|
|
3697
3696
|
|
|
3698
3697
|
var ObservableSetMarker = {};
|
|
3699
|
-
var ObservableSet
|
|
3700
|
-
function ObservableSet
|
|
3701
|
-
if (enhancer === void 0) { enhancer = deepEnhancer
|
|
3702
|
-
if (name === void 0) { name = "ObservableSet@" + getNextId
|
|
3698
|
+
var ObservableSet = /** @class */ (function () {
|
|
3699
|
+
function ObservableSet(initialData, enhancer, name) {
|
|
3700
|
+
if (enhancer === void 0) { enhancer = deepEnhancer; }
|
|
3701
|
+
if (name === void 0) { name = "ObservableSet@" + getNextId(); }
|
|
3703
3702
|
this.name = name;
|
|
3704
3703
|
this.$mobx = ObservableSetMarker;
|
|
3705
3704
|
this._data = new Set();
|
|
3706
|
-
this._atom = createAtom
|
|
3705
|
+
this._atom = createAtom(this.name);
|
|
3707
3706
|
if (typeof Set !== "function") {
|
|
3708
3707
|
throw new Error("mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js");
|
|
3709
3708
|
}
|
|
@@ -3712,29 +3711,29 @@ var ObservableSet$$1 = /** @class */ (function () {
|
|
|
3712
3711
|
this.replace(initialData);
|
|
3713
3712
|
}
|
|
3714
3713
|
}
|
|
3715
|
-
ObservableSet
|
|
3714
|
+
ObservableSet.prototype.dehanceValue = function (value) {
|
|
3716
3715
|
if (this.dehancer !== undefined) {
|
|
3717
3716
|
return this.dehancer(value);
|
|
3718
3717
|
}
|
|
3719
3718
|
return value;
|
|
3720
3719
|
};
|
|
3721
|
-
ObservableSet
|
|
3720
|
+
ObservableSet.prototype.clear = function () {
|
|
3722
3721
|
var _this = this;
|
|
3723
|
-
transaction
|
|
3724
|
-
untracked
|
|
3722
|
+
transaction(function () {
|
|
3723
|
+
untracked(function () {
|
|
3725
3724
|
_this._data.forEach(function (value) {
|
|
3726
3725
|
_this.delete(value);
|
|
3727
3726
|
});
|
|
3728
3727
|
});
|
|
3729
3728
|
});
|
|
3730
3729
|
};
|
|
3731
|
-
ObservableSet
|
|
3730
|
+
ObservableSet.prototype.forEach = function (callbackFn, thisArg) {
|
|
3732
3731
|
var _this = this;
|
|
3733
3732
|
this._data.forEach(function (value) {
|
|
3734
3733
|
callbackFn.call(thisArg, value, value, _this);
|
|
3735
3734
|
});
|
|
3736
3735
|
};
|
|
3737
|
-
Object.defineProperty(ObservableSet
|
|
3736
|
+
Object.defineProperty(ObservableSet.prototype, "size", {
|
|
3738
3737
|
get: function () {
|
|
3739
3738
|
this._atom.reportObserved();
|
|
3740
3739
|
return this._data.size;
|
|
@@ -3742,11 +3741,11 @@ var ObservableSet$$1 = /** @class */ (function () {
|
|
|
3742
3741
|
enumerable: true,
|
|
3743
3742
|
configurable: true
|
|
3744
3743
|
});
|
|
3745
|
-
ObservableSet
|
|
3744
|
+
ObservableSet.prototype.add = function (value) {
|
|
3746
3745
|
var _this = this;
|
|
3747
|
-
checkIfStateModificationsAreAllowed
|
|
3748
|
-
if (hasInterceptors
|
|
3749
|
-
var change = interceptChange
|
|
3746
|
+
checkIfStateModificationsAreAllowed(this._atom);
|
|
3747
|
+
if (hasInterceptors(this)) {
|
|
3748
|
+
var change = interceptChange(this, {
|
|
3750
3749
|
type: "add",
|
|
3751
3750
|
object: this,
|
|
3752
3751
|
newValue: value
|
|
@@ -3757,12 +3756,12 @@ var ObservableSet$$1 = /** @class */ (function () {
|
|
|
3757
3756
|
// changed by interceptor. Same applies for other Set and Map api's.
|
|
3758
3757
|
}
|
|
3759
3758
|
if (!this.has(value)) {
|
|
3760
|
-
transaction
|
|
3759
|
+
transaction(function () {
|
|
3761
3760
|
_this._data.add(_this.enhancer(value, undefined));
|
|
3762
3761
|
_this._atom.reportChanged();
|
|
3763
3762
|
});
|
|
3764
|
-
var notifySpy = isSpyEnabled
|
|
3765
|
-
var notify = hasListeners
|
|
3763
|
+
var notifySpy = isSpyEnabled();
|
|
3764
|
+
var notify = hasListeners(this);
|
|
3766
3765
|
var change = notify || notifySpy
|
|
3767
3766
|
? {
|
|
3768
3767
|
type: "add",
|
|
@@ -3771,18 +3770,18 @@ var ObservableSet$$1 = /** @class */ (function () {
|
|
|
3771
3770
|
}
|
|
3772
3771
|
: null;
|
|
3773
3772
|
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3774
|
-
spyReportStart
|
|
3773
|
+
spyReportStart(change);
|
|
3775
3774
|
if (notify)
|
|
3776
|
-
notifyListeners
|
|
3775
|
+
notifyListeners(this, change);
|
|
3777
3776
|
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3778
|
-
spyReportEnd
|
|
3777
|
+
spyReportEnd();
|
|
3779
3778
|
}
|
|
3780
3779
|
return this;
|
|
3781
3780
|
};
|
|
3782
|
-
ObservableSet
|
|
3781
|
+
ObservableSet.prototype.delete = function (value) {
|
|
3783
3782
|
var _this = this;
|
|
3784
|
-
if (hasInterceptors
|
|
3785
|
-
var change = interceptChange
|
|
3783
|
+
if (hasInterceptors(this)) {
|
|
3784
|
+
var change = interceptChange(this, {
|
|
3786
3785
|
type: "delete",
|
|
3787
3786
|
object: this,
|
|
3788
3787
|
oldValue: value
|
|
@@ -3791,8 +3790,8 @@ var ObservableSet$$1 = /** @class */ (function () {
|
|
|
3791
3790
|
return false;
|
|
3792
3791
|
}
|
|
3793
3792
|
if (this.has(value)) {
|
|
3794
|
-
var notifySpy = isSpyEnabled
|
|
3795
|
-
var notify = hasListeners
|
|
3793
|
+
var notifySpy = isSpyEnabled();
|
|
3794
|
+
var notify = hasListeners(this);
|
|
3796
3795
|
var change = notify || notifySpy
|
|
3797
3796
|
? {
|
|
3798
3797
|
type: "delete",
|
|
@@ -3801,54 +3800,54 @@ var ObservableSet$$1 = /** @class */ (function () {
|
|
|
3801
3800
|
}
|
|
3802
3801
|
: null;
|
|
3803
3802
|
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3804
|
-
spyReportStart
|
|
3805
|
-
transaction
|
|
3803
|
+
spyReportStart(__assign({}, change, { name: this.name }));
|
|
3804
|
+
transaction(function () {
|
|
3806
3805
|
_this._atom.reportChanged();
|
|
3807
3806
|
_this._data.delete(value);
|
|
3808
3807
|
});
|
|
3809
3808
|
if (notify)
|
|
3810
|
-
notifyListeners
|
|
3809
|
+
notifyListeners(this, change);
|
|
3811
3810
|
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3812
|
-
spyReportEnd
|
|
3811
|
+
spyReportEnd();
|
|
3813
3812
|
return true;
|
|
3814
3813
|
}
|
|
3815
3814
|
return false;
|
|
3816
3815
|
};
|
|
3817
|
-
ObservableSet
|
|
3816
|
+
ObservableSet.prototype.has = function (value) {
|
|
3818
3817
|
this._atom.reportObserved();
|
|
3819
3818
|
return this._data.has(this.dehanceValue(value));
|
|
3820
3819
|
};
|
|
3821
|
-
ObservableSet
|
|
3820
|
+
ObservableSet.prototype.entries = function () {
|
|
3822
3821
|
var nextIndex = 0;
|
|
3823
|
-
var keys
|
|
3824
|
-
var values
|
|
3825
|
-
return makeIterable
|
|
3822
|
+
var keys = iteratorToArray(this.keys());
|
|
3823
|
+
var values = iteratorToArray(this.values());
|
|
3824
|
+
return makeIterable({
|
|
3826
3825
|
next: function () {
|
|
3827
3826
|
var index = nextIndex;
|
|
3828
3827
|
nextIndex += 1;
|
|
3829
|
-
return index < values
|
|
3830
|
-
? { value: [keys
|
|
3828
|
+
return index < values.length
|
|
3829
|
+
? { value: [keys[index], values[index]], done: false }
|
|
3831
3830
|
: { done: true };
|
|
3832
3831
|
}
|
|
3833
3832
|
});
|
|
3834
3833
|
};
|
|
3835
|
-
ObservableSet
|
|
3834
|
+
ObservableSet.prototype.keys = function () {
|
|
3836
3835
|
return this.values();
|
|
3837
3836
|
};
|
|
3838
|
-
ObservableSet
|
|
3837
|
+
ObservableSet.prototype.values = function () {
|
|
3839
3838
|
this._atom.reportObserved();
|
|
3840
3839
|
var self = this;
|
|
3841
3840
|
var nextIndex = 0;
|
|
3842
3841
|
var observableValues;
|
|
3843
3842
|
if (this._data.values !== undefined) {
|
|
3844
|
-
observableValues = iteratorToArray
|
|
3843
|
+
observableValues = iteratorToArray(this._data.values());
|
|
3845
3844
|
}
|
|
3846
3845
|
else {
|
|
3847
3846
|
// There is no values function in IE11
|
|
3848
3847
|
observableValues = [];
|
|
3849
3848
|
this._data.forEach(function (e) { return observableValues.push(e); });
|
|
3850
3849
|
}
|
|
3851
|
-
return makeIterable
|
|
3850
|
+
return makeIterable({
|
|
3852
3851
|
next: function () {
|
|
3853
3852
|
return nextIndex < observableValues.length
|
|
3854
3853
|
? { value: self.dehanceValue(observableValues[nextIndex++]), done: false }
|
|
@@ -3856,57 +3855,57 @@ var ObservableSet$$1 = /** @class */ (function () {
|
|
|
3856
3855
|
}
|
|
3857
3856
|
});
|
|
3858
3857
|
};
|
|
3859
|
-
ObservableSet
|
|
3858
|
+
ObservableSet.prototype.replace = function (other) {
|
|
3860
3859
|
var _this = this;
|
|
3861
|
-
if (isObservableSet
|
|
3860
|
+
if (isObservableSet(other)) {
|
|
3862
3861
|
other = other.toJS();
|
|
3863
3862
|
}
|
|
3864
|
-
transaction
|
|
3863
|
+
transaction(function () {
|
|
3865
3864
|
if (Array.isArray(other)) {
|
|
3866
3865
|
_this.clear();
|
|
3867
3866
|
other.forEach(function (value) { return _this.add(value); });
|
|
3868
3867
|
}
|
|
3869
|
-
else if (isES6Set
|
|
3868
|
+
else if (isES6Set(other)) {
|
|
3870
3869
|
_this.clear();
|
|
3871
3870
|
other.forEach(function (value) { return _this.add(value); });
|
|
3872
3871
|
}
|
|
3873
3872
|
else if (other !== null && other !== undefined) {
|
|
3874
|
-
fail
|
|
3873
|
+
fail("Cannot initialize set from " + other);
|
|
3875
3874
|
}
|
|
3876
3875
|
});
|
|
3877
3876
|
return this;
|
|
3878
3877
|
};
|
|
3879
|
-
ObservableSet
|
|
3878
|
+
ObservableSet.prototype.observe = function (listener, fireImmediately) {
|
|
3880
3879
|
// TODO 'fireImmediately' can be true?
|
|
3881
3880
|
process.env.NODE_ENV !== "production" &&
|
|
3882
|
-
invariant
|
|
3883
|
-
return registerListener
|
|
3881
|
+
invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
|
|
3882
|
+
return registerListener(this, listener);
|
|
3884
3883
|
};
|
|
3885
|
-
ObservableSet
|
|
3886
|
-
return registerInterceptor
|
|
3884
|
+
ObservableSet.prototype.intercept = function (handler) {
|
|
3885
|
+
return registerInterceptor(this, handler);
|
|
3887
3886
|
};
|
|
3888
|
-
ObservableSet
|
|
3887
|
+
ObservableSet.prototype.toJS = function () {
|
|
3889
3888
|
return new Set(this);
|
|
3890
3889
|
};
|
|
3891
|
-
ObservableSet
|
|
3892
|
-
return this.name + "[ " + iteratorToArray
|
|
3890
|
+
ObservableSet.prototype.toString = function () {
|
|
3891
|
+
return this.name + "[ " + iteratorToArray(this.keys()).join(", ") + " ]";
|
|
3893
3892
|
};
|
|
3894
|
-
return ObservableSet
|
|
3893
|
+
return ObservableSet;
|
|
3895
3894
|
}());
|
|
3896
|
-
declareIterator
|
|
3895
|
+
declareIterator(ObservableSet.prototype, function () {
|
|
3897
3896
|
return this.values();
|
|
3898
3897
|
});
|
|
3899
|
-
addHiddenFinalProp
|
|
3900
|
-
var isObservableSet
|
|
3898
|
+
addHiddenFinalProp(ObservableSet.prototype, toStringTagSymbol(), "Set");
|
|
3899
|
+
var isObservableSet = createInstanceofPredicate("ObservableSet", ObservableSet);
|
|
3901
3900
|
|
|
3902
|
-
var ObservableObjectAdministration
|
|
3903
|
-
function ObservableObjectAdministration
|
|
3901
|
+
var ObservableObjectAdministration = /** @class */ (function () {
|
|
3902
|
+
function ObservableObjectAdministration(target, name, defaultEnhancer) {
|
|
3904
3903
|
this.target = target;
|
|
3905
3904
|
this.name = name;
|
|
3906
3905
|
this.defaultEnhancer = defaultEnhancer;
|
|
3907
3906
|
this.values = {};
|
|
3908
3907
|
}
|
|
3909
|
-
ObservableObjectAdministration
|
|
3908
|
+
ObservableObjectAdministration.prototype.read = function (owner, key) {
|
|
3910
3909
|
if (process.env.NODE_ENV === "production" && this.target !== owner) {
|
|
3911
3910
|
this.illegalAccess(owner, key);
|
|
3912
3911
|
if (!this.values[key])
|
|
@@ -3914,19 +3913,19 @@ var ObservableObjectAdministration$$1 = /** @class */ (function () {
|
|
|
3914
3913
|
}
|
|
3915
3914
|
return this.values[key].get();
|
|
3916
3915
|
};
|
|
3917
|
-
ObservableObjectAdministration
|
|
3916
|
+
ObservableObjectAdministration.prototype.write = function (owner, key, newValue) {
|
|
3918
3917
|
var instance = this.target;
|
|
3919
3918
|
if (process.env.NODE_ENV === "production" && instance !== owner) {
|
|
3920
3919
|
this.illegalAccess(owner, key);
|
|
3921
3920
|
}
|
|
3922
|
-
var observable
|
|
3923
|
-
if (observable
|
|
3924
|
-
observable
|
|
3921
|
+
var observable = this.values[key];
|
|
3922
|
+
if (observable instanceof ComputedValue) {
|
|
3923
|
+
observable.set(newValue);
|
|
3925
3924
|
return;
|
|
3926
3925
|
}
|
|
3927
3926
|
// intercept
|
|
3928
|
-
if (hasInterceptors
|
|
3929
|
-
var change = interceptChange
|
|
3927
|
+
if (hasInterceptors(this)) {
|
|
3928
|
+
var change = interceptChange(this, {
|
|
3930
3929
|
type: "update",
|
|
3931
3930
|
object: instance,
|
|
3932
3931
|
name: key,
|
|
@@ -3936,35 +3935,35 @@ var ObservableObjectAdministration$$1 = /** @class */ (function () {
|
|
|
3936
3935
|
return;
|
|
3937
3936
|
newValue = change.newValue;
|
|
3938
3937
|
}
|
|
3939
|
-
newValue = observable
|
|
3938
|
+
newValue = observable.prepareNewValue(newValue);
|
|
3940
3939
|
// notify spy & observers
|
|
3941
|
-
if (newValue !== globalState
|
|
3942
|
-
var notify = hasListeners
|
|
3943
|
-
var notifySpy = isSpyEnabled
|
|
3940
|
+
if (newValue !== globalState.UNCHANGED) {
|
|
3941
|
+
var notify = hasListeners(this);
|
|
3942
|
+
var notifySpy = isSpyEnabled();
|
|
3944
3943
|
var change = notify || notifySpy
|
|
3945
3944
|
? {
|
|
3946
3945
|
type: "update",
|
|
3947
3946
|
object: instance,
|
|
3948
|
-
oldValue: observable
|
|
3947
|
+
oldValue: observable.value,
|
|
3949
3948
|
name: key,
|
|
3950
3949
|
newValue: newValue
|
|
3951
3950
|
}
|
|
3952
3951
|
: null;
|
|
3953
3952
|
if (notifySpy)
|
|
3954
|
-
spyReportStart
|
|
3955
|
-
observable
|
|
3953
|
+
spyReportStart(__assign({}, change, { name: this.name, key: key }));
|
|
3954
|
+
observable.setNewValue(newValue);
|
|
3956
3955
|
if (notify)
|
|
3957
|
-
notifyListeners
|
|
3956
|
+
notifyListeners(this, change);
|
|
3958
3957
|
if (notifySpy)
|
|
3959
|
-
spyReportEnd
|
|
3958
|
+
spyReportEnd();
|
|
3960
3959
|
}
|
|
3961
3960
|
};
|
|
3962
|
-
ObservableObjectAdministration
|
|
3961
|
+
ObservableObjectAdministration.prototype.remove = function (key) {
|
|
3963
3962
|
if (!this.values[key])
|
|
3964
3963
|
return;
|
|
3965
3964
|
var target = this.target;
|
|
3966
|
-
if (hasInterceptors
|
|
3967
|
-
var change = interceptChange
|
|
3965
|
+
if (hasInterceptors(this)) {
|
|
3966
|
+
var change = interceptChange(this, {
|
|
3968
3967
|
object: target,
|
|
3969
3968
|
name: key,
|
|
3970
3969
|
type: "remove"
|
|
@@ -3973,9 +3972,9 @@ var ObservableObjectAdministration$$1 = /** @class */ (function () {
|
|
|
3973
3972
|
return;
|
|
3974
3973
|
}
|
|
3975
3974
|
try {
|
|
3976
|
-
startBatch
|
|
3977
|
-
var notify = hasListeners
|
|
3978
|
-
var notifySpy = isSpyEnabled
|
|
3975
|
+
startBatch();
|
|
3976
|
+
var notify = hasListeners(this);
|
|
3977
|
+
var notifySpy = isSpyEnabled();
|
|
3979
3978
|
var oldValue = this.values[key].get();
|
|
3980
3979
|
if (this.keys)
|
|
3981
3980
|
this.keys.remove(key);
|
|
@@ -3990,17 +3989,17 @@ var ObservableObjectAdministration$$1 = /** @class */ (function () {
|
|
|
3990
3989
|
}
|
|
3991
3990
|
: null;
|
|
3992
3991
|
if (notifySpy)
|
|
3993
|
-
spyReportStart
|
|
3992
|
+
spyReportStart(__assign({}, change, { name: this.name, key: key }));
|
|
3994
3993
|
if (notify)
|
|
3995
|
-
notifyListeners
|
|
3994
|
+
notifyListeners(this, change);
|
|
3996
3995
|
if (notifySpy)
|
|
3997
|
-
spyReportEnd
|
|
3996
|
+
spyReportEnd();
|
|
3998
3997
|
}
|
|
3999
3998
|
finally {
|
|
4000
|
-
endBatch
|
|
3999
|
+
endBatch();
|
|
4001
4000
|
}
|
|
4002
4001
|
};
|
|
4003
|
-
ObservableObjectAdministration
|
|
4002
|
+
ObservableObjectAdministration.prototype.illegalAccess = function (owner, propName) {
|
|
4004
4003
|
/**
|
|
4005
4004
|
* This happens if a property is accessed through the prototype chain, but the property was
|
|
4006
4005
|
* declared directly as own property on the prototype.
|
|
@@ -4027,44 +4026,44 @@ var ObservableObjectAdministration$$1 = /** @class */ (function () {
|
|
|
4027
4026
|
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/observe
|
|
4028
4027
|
* for callback details
|
|
4029
4028
|
*/
|
|
4030
|
-
ObservableObjectAdministration
|
|
4029
|
+
ObservableObjectAdministration.prototype.observe = function (callback, fireImmediately) {
|
|
4031
4030
|
process.env.NODE_ENV !== "production" &&
|
|
4032
|
-
invariant
|
|
4033
|
-
return registerListener
|
|
4031
|
+
invariant(fireImmediately !== true, "`observe` doesn't support the fire immediately property for observable objects.");
|
|
4032
|
+
return registerListener(this, callback);
|
|
4034
4033
|
};
|
|
4035
|
-
ObservableObjectAdministration
|
|
4036
|
-
return registerInterceptor
|
|
4034
|
+
ObservableObjectAdministration.prototype.intercept = function (handler) {
|
|
4035
|
+
return registerInterceptor(this, handler);
|
|
4037
4036
|
};
|
|
4038
|
-
ObservableObjectAdministration
|
|
4037
|
+
ObservableObjectAdministration.prototype.getKeys = function () {
|
|
4039
4038
|
var _this = this;
|
|
4040
4039
|
if (this.keys === undefined) {
|
|
4041
|
-
this.keys = (new ObservableArray
|
|
4040
|
+
this.keys = (new ObservableArray(Object.keys(this.values).filter(function (key) { return _this.values[key] instanceof ObservableValue; }), referenceEnhancer, "keys(" + this.name + ")", true));
|
|
4042
4041
|
}
|
|
4043
4042
|
return this.keys.slice();
|
|
4044
4043
|
};
|
|
4045
|
-
return ObservableObjectAdministration
|
|
4044
|
+
return ObservableObjectAdministration;
|
|
4046
4045
|
}());
|
|
4047
|
-
function asObservableObject
|
|
4046
|
+
function asObservableObject(target, name, defaultEnhancer) {
|
|
4048
4047
|
if (name === void 0) { name = ""; }
|
|
4049
|
-
if (defaultEnhancer === void 0) { defaultEnhancer = deepEnhancer
|
|
4048
|
+
if (defaultEnhancer === void 0) { defaultEnhancer = deepEnhancer; }
|
|
4050
4049
|
var adm = target.$mobx;
|
|
4051
4050
|
if (adm)
|
|
4052
4051
|
return adm;
|
|
4053
4052
|
process.env.NODE_ENV !== "production" &&
|
|
4054
|
-
invariant
|
|
4055
|
-
if (!isPlainObject
|
|
4056
|
-
name = (target.constructor.name || "ObservableObject") + "@" + getNextId
|
|
4053
|
+
invariant(Object.isExtensible(target), "Cannot make the designated object observable; it is not extensible");
|
|
4054
|
+
if (!isPlainObject(target))
|
|
4055
|
+
name = (target.constructor.name || "ObservableObject") + "@" + getNextId();
|
|
4057
4056
|
if (!name)
|
|
4058
|
-
name = "ObservableObject@" + getNextId
|
|
4059
|
-
adm = new ObservableObjectAdministration
|
|
4060
|
-
addHiddenFinalProp
|
|
4057
|
+
name = "ObservableObject@" + getNextId();
|
|
4058
|
+
adm = new ObservableObjectAdministration(target, name, defaultEnhancer);
|
|
4059
|
+
addHiddenFinalProp(target, "$mobx", adm);
|
|
4061
4060
|
return adm;
|
|
4062
4061
|
}
|
|
4063
|
-
function defineObservableProperty
|
|
4064
|
-
var adm = asObservableObject
|
|
4065
|
-
assertPropertyConfigurable
|
|
4066
|
-
if (hasInterceptors
|
|
4067
|
-
var change = interceptChange
|
|
4062
|
+
function defineObservableProperty(target, propName, newValue, enhancer) {
|
|
4063
|
+
var adm = asObservableObject(target);
|
|
4064
|
+
assertPropertyConfigurable(target, propName);
|
|
4065
|
+
if (hasInterceptors(adm)) {
|
|
4066
|
+
var change = interceptChange(adm, {
|
|
4068
4067
|
object: target,
|
|
4069
4068
|
name: propName,
|
|
4070
4069
|
type: "add",
|
|
@@ -4074,24 +4073,24 @@ function defineObservableProperty$$1(target, propName, newValue, enhancer) {
|
|
|
4074
4073
|
return;
|
|
4075
4074
|
newValue = change.newValue;
|
|
4076
4075
|
}
|
|
4077
|
-
var observable
|
|
4078
|
-
newValue = observable
|
|
4079
|
-
Object.defineProperty(target, propName, generateObservablePropConfig
|
|
4076
|
+
var observable = (adm.values[propName] = new ObservableValue(newValue, enhancer, adm.name + "." + propName, false));
|
|
4077
|
+
newValue = observable.value; // observableValue might have changed it
|
|
4078
|
+
Object.defineProperty(target, propName, generateObservablePropConfig(propName));
|
|
4080
4079
|
if (adm.keys)
|
|
4081
4080
|
adm.keys.push(propName);
|
|
4082
4081
|
notifyPropertyAddition(adm, target, propName, newValue);
|
|
4083
4082
|
}
|
|
4084
|
-
function defineComputedProperty
|
|
4083
|
+
function defineComputedProperty(target, // which objects holds the observable and provides `this` context?
|
|
4085
4084
|
propName, options) {
|
|
4086
|
-
var adm = asObservableObject
|
|
4085
|
+
var adm = asObservableObject(target);
|
|
4087
4086
|
options.name = adm.name + "." + propName;
|
|
4088
4087
|
options.context = target;
|
|
4089
|
-
adm.values[propName] = new ComputedValue
|
|
4090
|
-
Object.defineProperty(target, propName, generateComputedPropConfig
|
|
4088
|
+
adm.values[propName] = new ComputedValue(options);
|
|
4089
|
+
Object.defineProperty(target, propName, generateComputedPropConfig(propName));
|
|
4091
4090
|
}
|
|
4092
4091
|
var observablePropertyConfigs = Object.create(null);
|
|
4093
4092
|
var computedPropertyConfigs = Object.create(null);
|
|
4094
|
-
function generateObservablePropConfig
|
|
4093
|
+
function generateObservablePropConfig(propName) {
|
|
4095
4094
|
return (observablePropertyConfigs[propName] ||
|
|
4096
4095
|
(observablePropertyConfigs[propName] = {
|
|
4097
4096
|
configurable: true,
|
|
@@ -4109,15 +4108,15 @@ function getAdministrationForComputedPropOwner(owner) {
|
|
|
4109
4108
|
if (!adm) {
|
|
4110
4109
|
// because computed props are declared on proty,
|
|
4111
4110
|
// the current instance might not have been initialized yet
|
|
4112
|
-
initializeInstance
|
|
4111
|
+
initializeInstance(owner);
|
|
4113
4112
|
return owner.$mobx;
|
|
4114
4113
|
}
|
|
4115
4114
|
return adm;
|
|
4116
4115
|
}
|
|
4117
|
-
function generateComputedPropConfig
|
|
4116
|
+
function generateComputedPropConfig(propName) {
|
|
4118
4117
|
return (computedPropertyConfigs[propName] ||
|
|
4119
4118
|
(computedPropertyConfigs[propName] = {
|
|
4120
|
-
configurable:
|
|
4119
|
+
configurable: globalState.computedConfigurable,
|
|
4121
4120
|
enumerable: false,
|
|
4122
4121
|
get: function () {
|
|
4123
4122
|
return getAdministrationForComputedPropOwner(this).read(this, propName);
|
|
@@ -4128,8 +4127,8 @@ function generateComputedPropConfig$$1(propName) {
|
|
|
4128
4127
|
}));
|
|
4129
4128
|
}
|
|
4130
4129
|
function notifyPropertyAddition(adm, object, key, newValue) {
|
|
4131
|
-
var notify = hasListeners
|
|
4132
|
-
var notifySpy = isSpyEnabled
|
|
4130
|
+
var notify = hasListeners(adm);
|
|
4131
|
+
var notifySpy = isSpyEnabled();
|
|
4133
4132
|
var change = notify || notifySpy
|
|
4134
4133
|
? {
|
|
4135
4134
|
type: "add",
|
|
@@ -4139,96 +4138,96 @@ function notifyPropertyAddition(adm, object, key, newValue) {
|
|
|
4139
4138
|
}
|
|
4140
4139
|
: null;
|
|
4141
4140
|
if (notifySpy)
|
|
4142
|
-
spyReportStart
|
|
4141
|
+
spyReportStart(__assign({}, change, { name: adm.name, key: key }));
|
|
4143
4142
|
if (notify)
|
|
4144
|
-
notifyListeners
|
|
4143
|
+
notifyListeners(adm, change);
|
|
4145
4144
|
if (notifySpy)
|
|
4146
|
-
spyReportEnd
|
|
4145
|
+
spyReportEnd();
|
|
4147
4146
|
}
|
|
4148
|
-
var isObservableObjectAdministration = createInstanceofPredicate
|
|
4149
|
-
function isObservableObject
|
|
4150
|
-
if (isObject
|
|
4147
|
+
var isObservableObjectAdministration = createInstanceofPredicate("ObservableObjectAdministration", ObservableObjectAdministration);
|
|
4148
|
+
function isObservableObject(thing) {
|
|
4149
|
+
if (isObject(thing)) {
|
|
4151
4150
|
// Initializers run lazily when transpiling to babel, so make sure they are run...
|
|
4152
|
-
initializeInstance
|
|
4151
|
+
initializeInstance(thing);
|
|
4153
4152
|
return isObservableObjectAdministration(thing.$mobx);
|
|
4154
4153
|
}
|
|
4155
4154
|
return false;
|
|
4156
4155
|
}
|
|
4157
4156
|
|
|
4158
|
-
function getAtom
|
|
4157
|
+
function getAtom(thing, property) {
|
|
4159
4158
|
if (typeof thing === "object" && thing !== null) {
|
|
4160
|
-
if (isObservableArray
|
|
4159
|
+
if (isObservableArray(thing)) {
|
|
4161
4160
|
if (property !== undefined)
|
|
4162
|
-
fail
|
|
4161
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
4163
4162
|
"It is not possible to get index atoms from arrays");
|
|
4164
4163
|
return thing.$mobx.atom;
|
|
4165
4164
|
}
|
|
4166
|
-
if (isObservableSet
|
|
4165
|
+
if (isObservableSet(thing)) {
|
|
4167
4166
|
return thing.$mobx;
|
|
4168
4167
|
}
|
|
4169
|
-
if (isObservableMap
|
|
4168
|
+
if (isObservableMap(thing)) {
|
|
4170
4169
|
var anyThing = thing;
|
|
4171
4170
|
if (property === undefined)
|
|
4172
|
-
return getAtom
|
|
4173
|
-
var observable
|
|
4174
|
-
if (!observable
|
|
4175
|
-
fail
|
|
4176
|
-
"the entry '" + property + "' does not exist in the observable map '" + getDebugName
|
|
4177
|
-
return observable
|
|
4171
|
+
return getAtom(anyThing._keys);
|
|
4172
|
+
var observable = anyThing._data.get(property) || anyThing._hasMap.get(property);
|
|
4173
|
+
if (!observable)
|
|
4174
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
4175
|
+
"the entry '" + property + "' does not exist in the observable map '" + getDebugName(thing) + "'");
|
|
4176
|
+
return observable;
|
|
4178
4177
|
}
|
|
4179
4178
|
// Initializers run lazily when transpiling to babel, so make sure they are run...
|
|
4180
|
-
initializeInstance
|
|
4179
|
+
initializeInstance(thing);
|
|
4181
4180
|
if (property && !thing.$mobx)
|
|
4182
4181
|
thing[property]; // See #1072
|
|
4183
|
-
if (isObservableObject
|
|
4182
|
+
if (isObservableObject(thing)) {
|
|
4184
4183
|
if (!property)
|
|
4185
|
-
return fail
|
|
4186
|
-
var observable
|
|
4187
|
-
if (!observable
|
|
4188
|
-
fail
|
|
4189
|
-
"no observable property '" + property + "' found on the observable object '" + getDebugName
|
|
4190
|
-
return observable
|
|
4191
|
-
}
|
|
4192
|
-
if (isAtom
|
|
4184
|
+
return fail(process.env.NODE_ENV !== "production" && "please specify a property");
|
|
4185
|
+
var observable = thing.$mobx.values[property];
|
|
4186
|
+
if (!observable)
|
|
4187
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
4188
|
+
"no observable property '" + property + "' found on the observable object '" + getDebugName(thing) + "'");
|
|
4189
|
+
return observable;
|
|
4190
|
+
}
|
|
4191
|
+
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
|
|
4193
4192
|
return thing;
|
|
4194
4193
|
}
|
|
4195
4194
|
}
|
|
4196
4195
|
else if (typeof thing === "function") {
|
|
4197
|
-
if (isReaction
|
|
4196
|
+
if (isReaction(thing.$mobx)) {
|
|
4198
4197
|
// disposer function
|
|
4199
4198
|
return thing.$mobx;
|
|
4200
4199
|
}
|
|
4201
4200
|
}
|
|
4202
|
-
return fail
|
|
4201
|
+
return fail(process.env.NODE_ENV !== "production" && "Cannot obtain atom from " + thing);
|
|
4203
4202
|
}
|
|
4204
|
-
function getAdministration
|
|
4203
|
+
function getAdministration(thing, property) {
|
|
4205
4204
|
if (!thing)
|
|
4206
|
-
fail
|
|
4205
|
+
fail("Expecting some object");
|
|
4207
4206
|
if (property !== undefined)
|
|
4208
|
-
return getAdministration
|
|
4209
|
-
if (isAtom
|
|
4207
|
+
return getAdministration(getAtom(thing, property));
|
|
4208
|
+
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing))
|
|
4210
4209
|
return thing;
|
|
4211
|
-
if (isObservableMap
|
|
4210
|
+
if (isObservableMap(thing) || isObservableSet(thing))
|
|
4212
4211
|
return thing;
|
|
4213
4212
|
// Initializers run lazily when transpiling to babel, so make sure they are run...
|
|
4214
|
-
initializeInstance
|
|
4213
|
+
initializeInstance(thing);
|
|
4215
4214
|
if (thing.$mobx)
|
|
4216
4215
|
return thing.$mobx;
|
|
4217
|
-
fail
|
|
4216
|
+
fail(process.env.NODE_ENV !== "production" && "Cannot obtain administration from " + thing);
|
|
4218
4217
|
}
|
|
4219
|
-
function getDebugName
|
|
4218
|
+
function getDebugName(thing, property) {
|
|
4220
4219
|
var named;
|
|
4221
4220
|
if (property !== undefined)
|
|
4222
|
-
named = getAtom
|
|
4223
|
-
else if (isObservableObject
|
|
4224
|
-
named = getAdministration
|
|
4221
|
+
named = getAtom(thing, property);
|
|
4222
|
+
else if (isObservableObject(thing) || isObservableMap(thing) || isObservableSet(thing))
|
|
4223
|
+
named = getAdministration(thing);
|
|
4225
4224
|
else
|
|
4226
|
-
named = getAtom
|
|
4225
|
+
named = getAtom(thing); // valid for arrays as well
|
|
4227
4226
|
return named.name;
|
|
4228
4227
|
}
|
|
4229
4228
|
|
|
4230
4229
|
var toString = Object.prototype.toString;
|
|
4231
|
-
function deepEqual
|
|
4230
|
+
function deepEqual(a, b) {
|
|
4232
4231
|
return eq(a, b);
|
|
4233
4232
|
}
|
|
4234
4233
|
// Copied from https://github.com/jashkenas/underscore/blob/5c237a7c682fb68fd5378203f0bf22dce1624854/underscore.js#L1186-L1289
|
|
@@ -4331,15 +4330,15 @@ function deepEq(a, b, aStack, bStack) {
|
|
|
4331
4330
|
}
|
|
4332
4331
|
else {
|
|
4333
4332
|
// Deep compare objects.
|
|
4334
|
-
var keys
|
|
4333
|
+
var keys = Object.keys(a);
|
|
4335
4334
|
var key = void 0;
|
|
4336
|
-
length = keys
|
|
4335
|
+
length = keys.length;
|
|
4337
4336
|
// Ensure that both objects contain the same number of properties before comparing deep equality.
|
|
4338
4337
|
if (Object.keys(b).length !== length)
|
|
4339
4338
|
return false;
|
|
4340
4339
|
while (length--) {
|
|
4341
4340
|
// Deep compare each member
|
|
4342
|
-
key = keys
|
|
4341
|
+
key = keys[length];
|
|
4343
4342
|
if (!(has$1(b, key) && eq(a[key], b[key], aStack, bStack)))
|
|
4344
4343
|
return false;
|
|
4345
4344
|
}
|
|
@@ -4350,12 +4349,12 @@ function deepEq(a, b, aStack, bStack) {
|
|
|
4350
4349
|
return true;
|
|
4351
4350
|
}
|
|
4352
4351
|
function unwrap(a) {
|
|
4353
|
-
if (isObservableArray
|
|
4352
|
+
if (isObservableArray(a))
|
|
4354
4353
|
return a.peek();
|
|
4355
|
-
if (isES6Map
|
|
4356
|
-
return iteratorToArray
|
|
4357
|
-
if (isES6Set
|
|
4358
|
-
return iteratorToArray
|
|
4354
|
+
if (isES6Map(a) || isObservableMap(a))
|
|
4355
|
+
return iteratorToArray(a.entries());
|
|
4356
|
+
if (isES6Set(a) || isObservableSet(a))
|
|
4357
|
+
return iteratorToArray(a.entries());
|
|
4359
4358
|
return a;
|
|
4360
4359
|
}
|
|
4361
4360
|
function has$1(a, key) {
|
|
@@ -4400,26 +4399,24 @@ catch (e) {
|
|
|
4400
4399
|
g.process = {};
|
|
4401
4400
|
g.process.env = {};
|
|
4402
4401
|
}
|
|
4403
|
-
|
|
4404
4402
|
(function () {
|
|
4405
4403
|
function testCodeMinification() { }
|
|
4406
4404
|
if (testCodeMinification.name !== "testCodeMinification" &&
|
|
4407
4405
|
process.env.NODE_ENV !== "production" &&
|
|
4408
4406
|
process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
"[mobx] you are running a minified build, but '
|
|
4407
|
+
// trick so it doesn't get replaced
|
|
4408
|
+
var varName = ["process", "env", "NODE_ENV"].join(".");
|
|
4409
|
+
console.warn("[mobx] you are running a minified build, but '" + varName + "' was not set to 'production' in your bundler. This results in an unnecessarily large and slow bundle");
|
|
4412
4410
|
}
|
|
4413
4411
|
})();
|
|
4414
4412
|
// forward compatibility with mobx, so that packages can easily support mobx 4 & 5
|
|
4415
4413
|
var $mobx = "$mobx";
|
|
4416
|
-
// Devtools support
|
|
4417
4414
|
if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
|
|
4418
4415
|
// See: https://github.com/andykog/mobx-devtools/
|
|
4419
4416
|
__MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobx({
|
|
4420
|
-
spy: spy
|
|
4417
|
+
spy: spy,
|
|
4421
4418
|
extras: {
|
|
4422
|
-
getDebugName: getDebugName
|
|
4419
|
+
getDebugName: getDebugName
|
|
4423
4420
|
},
|
|
4424
4421
|
$mobx: $mobx
|
|
4425
4422
|
});
|
|
@@ -4459,7 +4456,7 @@ if (process.env.NODE_ENV !== "production" &&
|
|
|
4459
4456
|
Object.defineProperty(module.exports, prop, {
|
|
4460
4457
|
enumerable: false,
|
|
4461
4458
|
get: function () {
|
|
4462
|
-
fail
|
|
4459
|
+
fail("'" + prop + "' is no longer part of the public MobX api. Please consult the changelog to find out where this functionality went");
|
|
4463
4460
|
},
|
|
4464
4461
|
set: function () { }
|
|
4465
4462
|
});
|
|
@@ -4467,59 +4464,59 @@ if (process.env.NODE_ENV !== "production" &&
|
|
|
4467
4464
|
}
|
|
4468
4465
|
|
|
4469
4466
|
exports.$mobx = $mobx;
|
|
4470
|
-
exports.
|
|
4471
|
-
exports.
|
|
4472
|
-
exports.
|
|
4473
|
-
exports.
|
|
4474
|
-
exports.
|
|
4475
|
-
exports.
|
|
4476
|
-
exports.
|
|
4477
|
-
exports.
|
|
4478
|
-
exports.
|
|
4479
|
-
exports.
|
|
4480
|
-
exports.
|
|
4481
|
-
exports.
|
|
4482
|
-
exports.
|
|
4483
|
-
exports.
|
|
4484
|
-
exports.
|
|
4485
|
-
exports.
|
|
4486
|
-
exports.
|
|
4487
|
-
exports.
|
|
4488
|
-
exports.
|
|
4489
|
-
exports.
|
|
4490
|
-
exports.
|
|
4491
|
-
exports.
|
|
4492
|
-
exports.
|
|
4493
|
-
exports.
|
|
4494
|
-
exports.
|
|
4495
|
-
exports.
|
|
4496
|
-
exports.
|
|
4497
|
-
exports.
|
|
4498
|
-
exports.
|
|
4499
|
-
exports.
|
|
4500
|
-
exports.
|
|
4501
|
-
exports.
|
|
4502
|
-
exports.
|
|
4503
|
-
exports.
|
|
4504
|
-
exports.
|
|
4505
|
-
exports.
|
|
4506
|
-
exports.
|
|
4507
|
-
exports.
|
|
4508
|
-
exports.
|
|
4509
|
-
exports.
|
|
4510
|
-
exports.
|
|
4511
|
-
exports.
|
|
4512
|
-
exports.
|
|
4513
|
-
exports.
|
|
4514
|
-
exports.
|
|
4515
|
-
exports.
|
|
4516
|
-
exports.
|
|
4517
|
-
exports.
|
|
4518
|
-
exports.
|
|
4519
|
-
exports.
|
|
4520
|
-
exports.
|
|
4521
|
-
exports.
|
|
4522
|
-
exports.
|
|
4523
|
-
exports.
|
|
4524
|
-
exports.
|
|
4525
|
-
exports.
|
|
4467
|
+
exports.ObservableMap = ObservableMap;
|
|
4468
|
+
exports.ObservableSet = ObservableSet;
|
|
4469
|
+
exports.Reaction = Reaction;
|
|
4470
|
+
exports._allowStateChanges = allowStateChanges;
|
|
4471
|
+
exports._allowStateChangesInsideComputed = allowStateChangesInsideComputed;
|
|
4472
|
+
exports._getAdministration = getAdministration;
|
|
4473
|
+
exports._getGlobalState = getGlobalState;
|
|
4474
|
+
exports._interceptReads = interceptReads;
|
|
4475
|
+
exports._isComputingDerivation = isComputingDerivation;
|
|
4476
|
+
exports._resetGlobalState = resetGlobalState;
|
|
4477
|
+
exports.action = action;
|
|
4478
|
+
exports.autorun = autorun;
|
|
4479
|
+
exports.comparer = comparer;
|
|
4480
|
+
exports.computed = computed;
|
|
4481
|
+
exports.configure = configure;
|
|
4482
|
+
exports.createAtom = createAtom;
|
|
4483
|
+
exports.decorate = decorate;
|
|
4484
|
+
exports.entries = entries;
|
|
4485
|
+
exports.extendObservable = extendObservable;
|
|
4486
|
+
exports.extendShallowObservable = extendShallowObservable;
|
|
4487
|
+
exports.flow = flow;
|
|
4488
|
+
exports.get = get;
|
|
4489
|
+
exports.getAtom = getAtom;
|
|
4490
|
+
exports.getDebugName = getDebugName;
|
|
4491
|
+
exports.getDependencyTree = getDependencyTree;
|
|
4492
|
+
exports.getObserverTree = getObserverTree;
|
|
4493
|
+
exports.has = has;
|
|
4494
|
+
exports.intercept = intercept;
|
|
4495
|
+
exports.isAction = isAction;
|
|
4496
|
+
exports.isArrayLike = isArrayLike;
|
|
4497
|
+
exports.isBoxedObservable = isObservableValue;
|
|
4498
|
+
exports.isComputed = isComputed;
|
|
4499
|
+
exports.isComputedProp = isComputedProp;
|
|
4500
|
+
exports.isObservable = isObservable;
|
|
4501
|
+
exports.isObservableArray = isObservableArray;
|
|
4502
|
+
exports.isObservableMap = isObservableMap;
|
|
4503
|
+
exports.isObservableObject = isObservableObject;
|
|
4504
|
+
exports.isObservableProp = isObservableProp;
|
|
4505
|
+
exports.isObservableSet = isObservableSet;
|
|
4506
|
+
exports.keys = keys;
|
|
4507
|
+
exports.observable = observable;
|
|
4508
|
+
exports.observe = observe;
|
|
4509
|
+
exports.onBecomeObserved = onBecomeObserved;
|
|
4510
|
+
exports.onBecomeUnobserved = onBecomeUnobserved;
|
|
4511
|
+
exports.onReactionError = onReactionError;
|
|
4512
|
+
exports.reaction = reaction;
|
|
4513
|
+
exports.remove = remove;
|
|
4514
|
+
exports.runInAction = runInAction;
|
|
4515
|
+
exports.set = set;
|
|
4516
|
+
exports.spy = spy;
|
|
4517
|
+
exports.toJS = toJS;
|
|
4518
|
+
exports.trace = trace;
|
|
4519
|
+
exports.transaction = transaction;
|
|
4520
|
+
exports.untracked = untracked;
|
|
4521
|
+
exports.values = values;
|
|
4522
|
+
exports.when = when;
|