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