mobx 3.4.1 → 3.6.2
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/CHANGELOG.md +23 -1
- package/README.md +80 -19
- package/lib/api/autorun.d.ts +1 -1
- package/lib/api/whyrun.d.ts +3 -0
- package/lib/core/computedvalue.d.ts +5 -4
- package/lib/core/derivation.d.ts +6 -0
- package/lib/core/reaction.d.ts +4 -1
- package/lib/mobx.d.ts +103 -135
- package/lib/mobx.js +350 -215
- package/lib/mobx.js.flow +2 -2
- package/lib/mobx.min.js +2 -2
- package/lib/mobx.min.js.map +1 -1
- package/lib/mobx.module.js +350 -216
- package/lib/mobx.umd.js +350 -215
- package/lib/mobx.umd.min.js +2 -2
- package/lib/mobx.umd.min.js.map +1 -1
- package/lib/types/observablearray.d.ts +1 -1
- package/lib/utils/eq.d.ts +1 -0
- package/lib/utils/utils.d.ts +2 -7
- package/package.json +39 -25
package/lib/mobx.js
CHANGED
|
@@ -35,7 +35,7 @@ function __extends(d, b) {
|
|
|
35
35
|
* 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
|
|
36
36
|
* 2) they should notify mobx whenever they have _changed_. This way mobx can re-run any functions (derivations) that are using this atom.
|
|
37
37
|
*/
|
|
38
|
-
var BaseAtom = (function () {
|
|
38
|
+
var BaseAtom = /** @class */ (function () {
|
|
39
39
|
/**
|
|
40
40
|
* Create a new atom. For debugging purposes it is recommended to give it a name.
|
|
41
41
|
* The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
|
|
@@ -72,7 +72,7 @@ var BaseAtom = (function () {
|
|
|
72
72
|
};
|
|
73
73
|
return BaseAtom;
|
|
74
74
|
}());
|
|
75
|
-
var Atom = (function (_super) {
|
|
75
|
+
var Atom = /** @class */ (function (_super) {
|
|
76
76
|
__extends(Atom, _super);
|
|
77
77
|
/**
|
|
78
78
|
* Create a new atom. For debugging purposes it is recommended to give it a name.
|
|
@@ -238,7 +238,7 @@ var safariPrototypeSetterInheritanceBug = (function () {
|
|
|
238
238
|
*/
|
|
239
239
|
var OBSERVABLE_ARRAY_BUFFER_SIZE = 0;
|
|
240
240
|
// Typescript workaround to make sure ObservableArray extends Array
|
|
241
|
-
var StubArray = (function () {
|
|
241
|
+
var StubArray = /** @class */ (function () {
|
|
242
242
|
function StubArray() {
|
|
243
243
|
}
|
|
244
244
|
return StubArray;
|
|
@@ -281,7 +281,7 @@ if (Object.isFrozen(Array)) {
|
|
|
281
281
|
});
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
|
-
var ObservableArrayAdministration = (function () {
|
|
284
|
+
var ObservableArrayAdministration = /** @class */ (function () {
|
|
285
285
|
function ObservableArrayAdministration(name, enhancer, array, owned) {
|
|
286
286
|
this.array = array;
|
|
287
287
|
this.owned = owned;
|
|
@@ -444,7 +444,7 @@ var ObservableArrayAdministration = (function () {
|
|
|
444
444
|
};
|
|
445
445
|
return ObservableArrayAdministration;
|
|
446
446
|
}());
|
|
447
|
-
var ObservableArray = (function (_super) {
|
|
447
|
+
var ObservableArray = /** @class */ (function (_super) {
|
|
448
448
|
__extends(ObservableArray, _super);
|
|
449
449
|
function ObservableArray(initialValues, enhancer, name, owned) {
|
|
450
450
|
if (name === void 0) { name = "ObservableArray@" + getNextId(); }
|
|
@@ -757,7 +757,7 @@ function isObservableArray(thing) {
|
|
|
757
757
|
}
|
|
758
758
|
|
|
759
759
|
var UNCHANGED = {};
|
|
760
|
-
var ObservableValue = (function (_super) {
|
|
760
|
+
var ObservableValue = /** @class */ (function (_super) {
|
|
761
761
|
__extends(ObservableValue, _super);
|
|
762
762
|
function ObservableValue(value, enhancer, name, notifySpy) {
|
|
763
763
|
if (name === void 0) { name = "ObservableValue@" + getNextId(); }
|
|
@@ -998,18 +998,18 @@ function allowStateChangesEnd(prev) {
|
|
|
998
998
|
* This means that these properties despite being enumerable might not show up in Object.keys() (but they will show up in for...in loops).
|
|
999
999
|
*/
|
|
1000
1000
|
function createClassPropertyDecorator(
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1001
|
+
/**
|
|
1002
|
+
* This function is invoked once, when the property is added to a new instance.
|
|
1003
|
+
* When this happens is not strictly determined due to differences in TS and Babel:
|
|
1004
|
+
* Typescript: Usually when constructing the new instance
|
|
1005
|
+
* Babel, sometimes Typescript: during the first get / set
|
|
1006
|
+
* Both: when calling `runLazyInitializers(instance)`
|
|
1007
|
+
*/
|
|
1008
|
+
onInitialize, get, set, enumerable,
|
|
1009
|
+
/**
|
|
1010
|
+
* Can this decorator invoked with arguments? e.g. @decorator(args)
|
|
1011
|
+
*/
|
|
1012
|
+
allowCustomArguments) {
|
|
1013
1013
|
function classPropertyDecorator(target, key, descriptor, customArgs, argLen) {
|
|
1014
1014
|
if (argLen === void 0) { argLen = 0; }
|
|
1015
1015
|
invariant(allowCustomArguments || quacksLikeADecorator(arguments), "This function is a decorator, but it wasn't invoked like a decorator");
|
|
@@ -1171,6 +1171,138 @@ function defineBoundAction(target, propertyName, fn) {
|
|
|
1171
1171
|
addHiddenProp(target, propertyName, res);
|
|
1172
1172
|
}
|
|
1173
1173
|
|
|
1174
|
+
var toString = Object.prototype.toString;
|
|
1175
|
+
function deepEqual(a, b) {
|
|
1176
|
+
return eq(a, b);
|
|
1177
|
+
}
|
|
1178
|
+
// Copied from https://github.com/jashkenas/underscore/blob/5c237a7c682fb68fd5378203f0bf22dce1624854/underscore.js#L1186-L1289
|
|
1179
|
+
// Internal recursive comparison function for `isEqual`.
|
|
1180
|
+
function eq(a, b, aStack, bStack) {
|
|
1181
|
+
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
|
1182
|
+
// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
|
|
1183
|
+
if (a === b)
|
|
1184
|
+
return a !== 0 || 1 / a === 1 / b;
|
|
1185
|
+
// `null` or `undefined` only equal to itself (strict comparison).
|
|
1186
|
+
if (a == null || b == null)
|
|
1187
|
+
return false;
|
|
1188
|
+
// `NaN`s are equivalent, but non-reflexive.
|
|
1189
|
+
if (a !== a)
|
|
1190
|
+
return b !== b;
|
|
1191
|
+
// Exhaust primitive checks
|
|
1192
|
+
var type = typeof a;
|
|
1193
|
+
if (type !== "function" && type !== "object" && typeof b != "object")
|
|
1194
|
+
return false;
|
|
1195
|
+
return deepEq(a, b, aStack, bStack);
|
|
1196
|
+
}
|
|
1197
|
+
// Internal recursive comparison function for `isEqual`.
|
|
1198
|
+
function deepEq(a, b, aStack, bStack) {
|
|
1199
|
+
// Unwrap any wrapped objects.
|
|
1200
|
+
a = unwrap(a);
|
|
1201
|
+
b = unwrap(b);
|
|
1202
|
+
// Compare `[[Class]]` names.
|
|
1203
|
+
var className = toString.call(a);
|
|
1204
|
+
if (className !== toString.call(b))
|
|
1205
|
+
return false;
|
|
1206
|
+
switch (className) {
|
|
1207
|
+
// Strings, numbers, regular expressions, dates, and booleans are compared by value.
|
|
1208
|
+
case "[object RegExp]":
|
|
1209
|
+
// RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
|
|
1210
|
+
case "[object String]":
|
|
1211
|
+
// Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
|
|
1212
|
+
// equivalent to `new String("5")`.
|
|
1213
|
+
return "" + a === "" + b;
|
|
1214
|
+
case "[object Number]":
|
|
1215
|
+
// `NaN`s are equivalent, but non-reflexive.
|
|
1216
|
+
// Object(NaN) is equivalent to NaN.
|
|
1217
|
+
if (+a !== +a)
|
|
1218
|
+
return +b !== +b;
|
|
1219
|
+
// An `egal` comparison is performed for other numeric values.
|
|
1220
|
+
return +a === 0 ? 1 / +a === 1 / b : +a === +b;
|
|
1221
|
+
case "[object Date]":
|
|
1222
|
+
case "[object Boolean]":
|
|
1223
|
+
// Coerce dates and booleans to numeric primitive values. Dates are compared by their
|
|
1224
|
+
// millisecond representations. Note that invalid dates with millisecond representations
|
|
1225
|
+
// of `NaN` are not equivalent.
|
|
1226
|
+
return +a === +b;
|
|
1227
|
+
case "[object Symbol]":
|
|
1228
|
+
return (typeof Symbol !== "undefined" && Symbol.valueOf.call(a) === Symbol.valueOf.call(b));
|
|
1229
|
+
}
|
|
1230
|
+
var areArrays = className === "[object Array]";
|
|
1231
|
+
if (!areArrays) {
|
|
1232
|
+
if (typeof a != "object" || typeof b != "object")
|
|
1233
|
+
return false;
|
|
1234
|
+
// Objects with different constructors are not equivalent, but `Object`s or `Array`s
|
|
1235
|
+
// from different frames are.
|
|
1236
|
+
var aCtor = a.constructor, bCtor = b.constructor;
|
|
1237
|
+
if (aCtor !== bCtor &&
|
|
1238
|
+
!(typeof aCtor === "function" &&
|
|
1239
|
+
aCtor instanceof aCtor &&
|
|
1240
|
+
typeof bCtor === "function" &&
|
|
1241
|
+
bCtor instanceof bCtor) &&
|
|
1242
|
+
("constructor" in a && "constructor" in b)) {
|
|
1243
|
+
return false;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
|
1247
|
+
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
|
1248
|
+
// Initializing stack of traversed objects.
|
|
1249
|
+
// It's done here since we only need them for objects and arrays comparison.
|
|
1250
|
+
aStack = aStack || [];
|
|
1251
|
+
bStack = bStack || [];
|
|
1252
|
+
var length = aStack.length;
|
|
1253
|
+
while (length--) {
|
|
1254
|
+
// Linear search. Performance is inversely proportional to the number of
|
|
1255
|
+
// unique nested structures.
|
|
1256
|
+
if (aStack[length] === a)
|
|
1257
|
+
return bStack[length] === b;
|
|
1258
|
+
}
|
|
1259
|
+
// Add the first object to the stack of traversed objects.
|
|
1260
|
+
aStack.push(a);
|
|
1261
|
+
bStack.push(b);
|
|
1262
|
+
// Recursively compare objects and arrays.
|
|
1263
|
+
if (areArrays) {
|
|
1264
|
+
// Compare array lengths to determine if a deep comparison is necessary.
|
|
1265
|
+
length = a.length;
|
|
1266
|
+
if (length !== b.length)
|
|
1267
|
+
return false;
|
|
1268
|
+
// Deep compare the contents, ignoring non-numeric properties.
|
|
1269
|
+
while (length--) {
|
|
1270
|
+
if (!eq(a[length], b[length], aStack, bStack))
|
|
1271
|
+
return false;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
else {
|
|
1275
|
+
// Deep compare objects.
|
|
1276
|
+
var keys = Object.keys(a), key;
|
|
1277
|
+
length = keys.length;
|
|
1278
|
+
// Ensure that both objects contain the same number of properties before comparing deep equality.
|
|
1279
|
+
if (Object.keys(b).length !== length)
|
|
1280
|
+
return false;
|
|
1281
|
+
while (length--) {
|
|
1282
|
+
// Deep compare each member
|
|
1283
|
+
key = keys[length];
|
|
1284
|
+
if (!(has(b, key) && eq(a[key], b[key], aStack, bStack)))
|
|
1285
|
+
return false;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
// Remove the first object from the stack of traversed objects.
|
|
1289
|
+
aStack.pop();
|
|
1290
|
+
bStack.pop();
|
|
1291
|
+
return true;
|
|
1292
|
+
}
|
|
1293
|
+
function unwrap(a) {
|
|
1294
|
+
if (isObservableArray(a))
|
|
1295
|
+
return a.peek();
|
|
1296
|
+
if (isObservableMap(a))
|
|
1297
|
+
return a.entries();
|
|
1298
|
+
if (isES6Map(a))
|
|
1299
|
+
return iteratorToArray(a.entries());
|
|
1300
|
+
return a;
|
|
1301
|
+
}
|
|
1302
|
+
function has(a, key) {
|
|
1303
|
+
return Object.prototype.hasOwnProperty.call(a, key);
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1174
1306
|
function identityComparer(a, b) {
|
|
1175
1307
|
return a === b;
|
|
1176
1308
|
}
|
|
@@ -1352,7 +1484,7 @@ function reaction(expression, effect, arg3) {
|
|
|
1352
1484
|
*
|
|
1353
1485
|
* If at any point it's outside batch and it isn't observed: reset everything and go to 1.
|
|
1354
1486
|
*/
|
|
1355
|
-
var ComputedValue = (function () {
|
|
1487
|
+
var ComputedValue = /** @class */ (function () {
|
|
1356
1488
|
/**
|
|
1357
1489
|
* Create a new computed value based on a function expression.
|
|
1358
1490
|
*
|
|
@@ -1384,6 +1516,7 @@ var ComputedValue = (function () {
|
|
|
1384
1516
|
this.value = new CaughtException(null);
|
|
1385
1517
|
this.isComputing = false; // to check for cycles
|
|
1386
1518
|
this.isRunningSetter = false;
|
|
1519
|
+
this.isTracing = TraceMode.NONE;
|
|
1387
1520
|
this.name = name || "ComputedValue@" + getNextId();
|
|
1388
1521
|
if (setter)
|
|
1389
1522
|
this.setter = createAction(name + "-setter", setter);
|
|
@@ -1406,8 +1539,13 @@ var ComputedValue = (function () {
|
|
|
1406
1539
|
// The computedValue is accessed outside of any mobx stuff. Batch observing should be enough and don't need
|
|
1407
1540
|
// tracking as it will never be called again inside this batch.
|
|
1408
1541
|
startBatch();
|
|
1409
|
-
if (shouldCompute(this))
|
|
1542
|
+
if (shouldCompute(this)) {
|
|
1543
|
+
if (this.isTracing !== TraceMode.NONE) {
|
|
1544
|
+
console.log("[mobx.trace] '" + this
|
|
1545
|
+
.name + "' is being read outside a reactive context and doing a full recompute");
|
|
1546
|
+
}
|
|
1410
1547
|
this.value = this.computeValue(false);
|
|
1548
|
+
}
|
|
1411
1549
|
endBatch();
|
|
1412
1550
|
}
|
|
1413
1551
|
else {
|
|
@@ -1452,7 +1590,8 @@ var ComputedValue = (function () {
|
|
|
1452
1590
|
});
|
|
1453
1591
|
}
|
|
1454
1592
|
var oldValue = this.value;
|
|
1455
|
-
var wasSuspended =
|
|
1593
|
+
var wasSuspended =
|
|
1594
|
+
/* see #1208 */ this.dependenciesState === exports.IDerivationState.NOT_TRACKING;
|
|
1456
1595
|
var newValue = (this.value = this.computeValue(true));
|
|
1457
1596
|
return (wasSuspended ||
|
|
1458
1597
|
isCaughtException(oldValue) ||
|
|
@@ -1527,7 +1666,7 @@ var ComputedValue = (function () {
|
|
|
1527
1666
|
ComputedValue.prototype[primitiveSymbol()] = ComputedValue.prototype.valueOf;
|
|
1528
1667
|
var isComputedValue = createInstanceofPredicate("ComputedValue", ComputedValue);
|
|
1529
1668
|
|
|
1530
|
-
var ObservableObjectAdministration = (function () {
|
|
1669
|
+
var ObservableObjectAdministration = /** @class */ (function () {
|
|
1531
1670
|
function ObservableObjectAdministration(target, name) {
|
|
1532
1671
|
this.target = target;
|
|
1533
1672
|
this.name = name;
|
|
@@ -2027,7 +2166,7 @@ function transaction(action, thisArg) {
|
|
|
2027
2166
|
}
|
|
2028
2167
|
|
|
2029
2168
|
var ObservableMapMarker = {};
|
|
2030
|
-
var ObservableMap = (function () {
|
|
2169
|
+
var ObservableMap = /** @class */ (function () {
|
|
2031
2170
|
function ObservableMap(initialData, enhancer, name) {
|
|
2032
2171
|
if (enhancer === void 0) { enhancer = deepEnhancer; }
|
|
2033
2172
|
if (name === void 0) { name = "ObservableMap@" + getNextId(); }
|
|
@@ -2420,71 +2559,6 @@ function isPropertyConfigurable(object, prop) {
|
|
|
2420
2559
|
function assertPropertyConfigurable(object, prop) {
|
|
2421
2560
|
invariant(isPropertyConfigurable(object, prop), "Cannot make property '" + prop + "' observable, it is not configurable and writable in the target object");
|
|
2422
2561
|
}
|
|
2423
|
-
function getEnumerableKeys(obj) {
|
|
2424
|
-
var res = [];
|
|
2425
|
-
for (var key in obj)
|
|
2426
|
-
res.push(key);
|
|
2427
|
-
return res;
|
|
2428
|
-
}
|
|
2429
|
-
/**
|
|
2430
|
-
* Naive deepEqual. Doesn't check for prototype, non-enumerable or out-of-range properties on arrays.
|
|
2431
|
-
* If you have such a case, you probably should use this function but something fancier :).
|
|
2432
|
-
*/
|
|
2433
|
-
function deepEqual(a, b) {
|
|
2434
|
-
if (a === null && b === null)
|
|
2435
|
-
return true;
|
|
2436
|
-
if (a === undefined && b === undefined)
|
|
2437
|
-
return true;
|
|
2438
|
-
if (areBothNaN(a, b))
|
|
2439
|
-
return true;
|
|
2440
|
-
if (typeof a !== "object")
|
|
2441
|
-
return a === b;
|
|
2442
|
-
var aIsArray = isArrayLike(a);
|
|
2443
|
-
var aIsMap = isMapLike(a);
|
|
2444
|
-
if (aIsArray !== isArrayLike(b)) {
|
|
2445
|
-
return false;
|
|
2446
|
-
}
|
|
2447
|
-
else if (aIsMap !== isMapLike(b)) {
|
|
2448
|
-
return false;
|
|
2449
|
-
}
|
|
2450
|
-
else if (aIsArray) {
|
|
2451
|
-
if (a.length !== b.length)
|
|
2452
|
-
return false;
|
|
2453
|
-
for (var i = a.length - 1; i >= 0; i--)
|
|
2454
|
-
if (!deepEqual(a[i], b[i]))
|
|
2455
|
-
return false;
|
|
2456
|
-
return true;
|
|
2457
|
-
}
|
|
2458
|
-
else if (aIsMap) {
|
|
2459
|
-
if (a.size !== b.size)
|
|
2460
|
-
return false;
|
|
2461
|
-
var equals_1 = true;
|
|
2462
|
-
a.forEach(function (value, key) {
|
|
2463
|
-
equals_1 = equals_1 && deepEqual(b.get(key), value);
|
|
2464
|
-
});
|
|
2465
|
-
return equals_1;
|
|
2466
|
-
}
|
|
2467
|
-
else if (typeof a === "object" && typeof b === "object") {
|
|
2468
|
-
if (a === null || b === null)
|
|
2469
|
-
return false;
|
|
2470
|
-
if (isMapLike(a) && isMapLike(b)) {
|
|
2471
|
-
if (a.size !== b.size)
|
|
2472
|
-
return false;
|
|
2473
|
-
// Freaking inefficient.... Create PR if you run into this :) Much appreciated!
|
|
2474
|
-
return deepEqual(observable.shallowMap(a).entries(), observable.shallowMap(b).entries());
|
|
2475
|
-
}
|
|
2476
|
-
if (getEnumerableKeys(a).length !== getEnumerableKeys(b).length)
|
|
2477
|
-
return false;
|
|
2478
|
-
for (var prop in a) {
|
|
2479
|
-
if (!(prop in b))
|
|
2480
|
-
return false;
|
|
2481
|
-
if (!deepEqual(a[prop], b[prop]))
|
|
2482
|
-
return false;
|
|
2483
|
-
}
|
|
2484
|
-
return true;
|
|
2485
|
-
}
|
|
2486
|
-
return false;
|
|
2487
|
-
}
|
|
2488
2562
|
function createInstanceofPredicate(name, clazz) {
|
|
2489
2563
|
var propName = "isMobX" + name;
|
|
2490
2564
|
clazz.prototype[propName] = true;
|
|
@@ -2493,7 +2567,7 @@ function createInstanceofPredicate(name, clazz) {
|
|
|
2493
2567
|
};
|
|
2494
2568
|
}
|
|
2495
2569
|
function areBothNaN(a, b) {
|
|
2496
|
-
return
|
|
2570
|
+
return typeof a === "number" && typeof b === "number" && isNaN(a) && isNaN(b);
|
|
2497
2571
|
}
|
|
2498
2572
|
/**
|
|
2499
2573
|
* Returns whether the argument is an array, disregarding observability.
|
|
@@ -2501,28 +2575,34 @@ function areBothNaN(a, b) {
|
|
|
2501
2575
|
function isArrayLike(x) {
|
|
2502
2576
|
return Array.isArray(x) || isObservableArray(x);
|
|
2503
2577
|
}
|
|
2504
|
-
function isMapLike(x) {
|
|
2505
|
-
return isES6Map(x) || isObservableMap(x);
|
|
2506
|
-
}
|
|
2507
2578
|
function isES6Map(thing) {
|
|
2508
2579
|
if (getGlobal().Map !== undefined && thing instanceof getGlobal().Map)
|
|
2509
2580
|
return true;
|
|
2510
2581
|
return false;
|
|
2511
2582
|
}
|
|
2512
2583
|
function getMapLikeKeys(map$$1) {
|
|
2513
|
-
var keys;
|
|
2514
2584
|
if (isPlainObject(map$$1))
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2585
|
+
return Object.keys(map$$1);
|
|
2586
|
+
if (Array.isArray(map$$1))
|
|
2587
|
+
return map$$1.map(function (_a) {
|
|
2518
2588
|
var key = _a[0];
|
|
2519
2589
|
return key;
|
|
2520
2590
|
});
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
return keys;
|
|
2591
|
+
if (isES6Map(map$$1))
|
|
2592
|
+
return Array.from(map$$1.keys());
|
|
2593
|
+
if (isObservableMap(map$$1))
|
|
2594
|
+
return map$$1.keys();
|
|
2595
|
+
return fail("Cannot get keys from " + map$$1);
|
|
2596
|
+
}
|
|
2597
|
+
function iteratorToArray(it) {
|
|
2598
|
+
var res = [];
|
|
2599
|
+
while (true) {
|
|
2600
|
+
var r = it.next();
|
|
2601
|
+
if (r.done)
|
|
2602
|
+
break;
|
|
2603
|
+
res.push(r.value);
|
|
2604
|
+
}
|
|
2605
|
+
return res;
|
|
2526
2606
|
}
|
|
2527
2607
|
function primitiveSymbol() {
|
|
2528
2608
|
return (typeof Symbol === "function" && Symbol.toPrimitive) || "@@toPrimitive";
|
|
@@ -2535,7 +2615,7 @@ function toPrimitive(value) {
|
|
|
2535
2615
|
* These values will persist if global state is reset
|
|
2536
2616
|
*/
|
|
2537
2617
|
var persistentKeys = ["mobxGuid", "resetId", "spyListeners", "strictMode", "runId"];
|
|
2538
|
-
var MobXGlobals = (function () {
|
|
2618
|
+
var MobXGlobals = /** @class */ (function () {
|
|
2539
2619
|
function MobXGlobals() {
|
|
2540
2620
|
/**
|
|
2541
2621
|
* MobXGlobals version.
|
|
@@ -2619,7 +2699,7 @@ var warnedAboutMultipleInstances = false;
|
|
|
2619
2699
|
warnedAboutMultipleInstances = true;
|
|
2620
2700
|
console.warn("[mobx] Warning: there are multiple mobx instances active. This might lead to unexpected results. See https://github.com/mobxjs/mobx/issues/1082 for details.");
|
|
2621
2701
|
}
|
|
2622
|
-
});
|
|
2702
|
+
}, 1);
|
|
2623
2703
|
}
|
|
2624
2704
|
}
|
|
2625
2705
|
function isolateGlobalState() {
|
|
@@ -2661,6 +2741,91 @@ function resetGlobalState() {
|
|
|
2661
2741
|
globalState.allowStateChanges = !globalState.strictMode;
|
|
2662
2742
|
}
|
|
2663
2743
|
|
|
2744
|
+
function getAtom(thing, property) {
|
|
2745
|
+
if (typeof thing === "object" && thing !== null) {
|
|
2746
|
+
if (isObservableArray(thing)) {
|
|
2747
|
+
invariant(property === undefined, getMessage("m036"));
|
|
2748
|
+
return thing.$mobx.atom;
|
|
2749
|
+
}
|
|
2750
|
+
if (isObservableMap(thing)) {
|
|
2751
|
+
var anyThing = thing;
|
|
2752
|
+
if (property === undefined)
|
|
2753
|
+
return getAtom(anyThing._keys);
|
|
2754
|
+
var observable = anyThing._data[property] || anyThing._hasMap[property];
|
|
2755
|
+
invariant(!!observable, "the entry '" + property + "' does not exist in the observable map '" + getDebugName(thing) + "'");
|
|
2756
|
+
return observable;
|
|
2757
|
+
}
|
|
2758
|
+
// Initializers run lazily when transpiling to babel, so make sure they are run...
|
|
2759
|
+
runLazyInitializers(thing);
|
|
2760
|
+
if (property && !thing.$mobx)
|
|
2761
|
+
thing[property]; // See #1072 // TODO: remove in 4.0
|
|
2762
|
+
if (isObservableObject(thing)) {
|
|
2763
|
+
if (!property)
|
|
2764
|
+
return fail("please specify a property");
|
|
2765
|
+
var observable = thing.$mobx.values[property];
|
|
2766
|
+
invariant(!!observable, "no observable property '" + property + "' found on the observable object '" + getDebugName(thing) + "'");
|
|
2767
|
+
return observable;
|
|
2768
|
+
}
|
|
2769
|
+
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
|
|
2770
|
+
return thing;
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
else if (typeof thing === "function") {
|
|
2774
|
+
if (isReaction(thing.$mobx)) {
|
|
2775
|
+
// disposer function
|
|
2776
|
+
return thing.$mobx;
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
return fail("Cannot obtain atom from " + thing);
|
|
2780
|
+
}
|
|
2781
|
+
function getAdministration(thing, property) {
|
|
2782
|
+
invariant(thing, "Expecting some object");
|
|
2783
|
+
if (property !== undefined)
|
|
2784
|
+
return getAdministration(getAtom(thing, property));
|
|
2785
|
+
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing))
|
|
2786
|
+
return thing;
|
|
2787
|
+
if (isObservableMap(thing))
|
|
2788
|
+
return thing;
|
|
2789
|
+
// Initializers run lazily when transpiling to babel, so make sure they are run...
|
|
2790
|
+
runLazyInitializers(thing);
|
|
2791
|
+
if (thing.$mobx)
|
|
2792
|
+
return thing.$mobx;
|
|
2793
|
+
invariant(false, "Cannot obtain administration from " + thing);
|
|
2794
|
+
}
|
|
2795
|
+
function getDebugName(thing, property) {
|
|
2796
|
+
var named;
|
|
2797
|
+
if (property !== undefined)
|
|
2798
|
+
named = getAtom(thing, property);
|
|
2799
|
+
else if (isObservableObject(thing) || isObservableMap(thing))
|
|
2800
|
+
named = getAdministration(thing);
|
|
2801
|
+
else
|
|
2802
|
+
named = getAtom(thing); // valid for arrays as well
|
|
2803
|
+
return named.name;
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
function getDependencyTree(thing, property) {
|
|
2807
|
+
return nodeToDependencyTree(getAtom(thing, property));
|
|
2808
|
+
}
|
|
2809
|
+
function nodeToDependencyTree(node) {
|
|
2810
|
+
var result = {
|
|
2811
|
+
name: node.name
|
|
2812
|
+
};
|
|
2813
|
+
if (node.observing && node.observing.length > 0)
|
|
2814
|
+
result.dependencies = unique(node.observing).map(nodeToDependencyTree);
|
|
2815
|
+
return result;
|
|
2816
|
+
}
|
|
2817
|
+
function getObserverTree(thing, property) {
|
|
2818
|
+
return nodeToObserverTree(getAtom(thing, property));
|
|
2819
|
+
}
|
|
2820
|
+
function nodeToObserverTree(node) {
|
|
2821
|
+
var result = {
|
|
2822
|
+
name: node.name
|
|
2823
|
+
};
|
|
2824
|
+
if (hasObservers(node))
|
|
2825
|
+
result.observers = getObservers(node).map(nodeToObserverTree);
|
|
2826
|
+
return result;
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2664
2829
|
function hasObservers(observable) {
|
|
2665
2830
|
return observable.observers && observable.observers.length > 0;
|
|
2666
2831
|
}
|
|
@@ -2779,8 +2944,12 @@ function propagateChanged(observable) {
|
|
|
2779
2944
|
var i = observers.length;
|
|
2780
2945
|
while (i--) {
|
|
2781
2946
|
var d = observers[i];
|
|
2782
|
-
if (d.dependenciesState === exports.IDerivationState.UP_TO_DATE)
|
|
2947
|
+
if (d.dependenciesState === exports.IDerivationState.UP_TO_DATE) {
|
|
2948
|
+
if (d.isTracing !== TraceMode.NONE) {
|
|
2949
|
+
logTraceInfo(d, observable);
|
|
2950
|
+
}
|
|
2783
2951
|
d.onBecomeStale();
|
|
2952
|
+
}
|
|
2784
2953
|
d.dependenciesState = exports.IDerivationState.STALE;
|
|
2785
2954
|
}
|
|
2786
2955
|
// invariantLOS(observable, "changed end");
|
|
@@ -2815,11 +2984,32 @@ function propagateMaybeChanged(observable) {
|
|
|
2815
2984
|
var d = observers[i];
|
|
2816
2985
|
if (d.dependenciesState === exports.IDerivationState.UP_TO_DATE) {
|
|
2817
2986
|
d.dependenciesState = exports.IDerivationState.POSSIBLY_STALE;
|
|
2987
|
+
if (d.isTracing !== TraceMode.NONE) {
|
|
2988
|
+
logTraceInfo(d, observable);
|
|
2989
|
+
}
|
|
2818
2990
|
d.onBecomeStale();
|
|
2819
2991
|
}
|
|
2820
2992
|
}
|
|
2821
2993
|
// invariantLOS(observable, "maybe end");
|
|
2822
2994
|
}
|
|
2995
|
+
function logTraceInfo(derivation, observable) {
|
|
2996
|
+
console.log("[mobx.trace] '" + derivation.name + "' is invalidated due to a change in: '" + observable.name + "'");
|
|
2997
|
+
if (derivation.isTracing === TraceMode.BREAK) {
|
|
2998
|
+
var lines = [];
|
|
2999
|
+
printDepTree(getDependencyTree(derivation), lines, 1);
|
|
3000
|
+
// prettier-ignore
|
|
3001
|
+
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() : "") + "\n\nThe dependencies for this derivation are:\n\n" + lines.join("\n") + "\n*/\n ")();
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
function printDepTree(tree, lines, depth) {
|
|
3005
|
+
if (lines.length >= 1000) {
|
|
3006
|
+
lines.push("(and many more)");
|
|
3007
|
+
return;
|
|
3008
|
+
}
|
|
3009
|
+
lines.push("" + new Array(depth).join("\t") + tree.name); // MWE: not the fastest, but the easiest way :)
|
|
3010
|
+
if (tree.dependencies)
|
|
3011
|
+
tree.dependencies.forEach(function (child) { return printDepTree(child, lines, depth + 1); });
|
|
3012
|
+
}
|
|
2823
3013
|
|
|
2824
3014
|
(function (IDerivationState) {
|
|
2825
3015
|
// before being run or (outside batch and not being observed)
|
|
@@ -2840,7 +3030,13 @@ function propagateMaybeChanged(observable) {
|
|
|
2840
3030
|
// will need to recompute when it's needed next.
|
|
2841
3031
|
IDerivationState[IDerivationState["STALE"] = 2] = "STALE";
|
|
2842
3032
|
})(exports.IDerivationState || (exports.IDerivationState = {}));
|
|
2843
|
-
var
|
|
3033
|
+
var TraceMode;
|
|
3034
|
+
(function (TraceMode) {
|
|
3035
|
+
TraceMode[TraceMode["NONE"] = 0] = "NONE";
|
|
3036
|
+
TraceMode[TraceMode["LOG"] = 1] = "LOG";
|
|
3037
|
+
TraceMode[TraceMode["BREAK"] = 2] = "BREAK";
|
|
3038
|
+
})(TraceMode || (TraceMode = {}));
|
|
3039
|
+
var CaughtException = /** @class */ (function () {
|
|
2844
3040
|
function CaughtException(cause) {
|
|
2845
3041
|
this.cause = cause;
|
|
2846
3042
|
// Empty
|
|
@@ -3028,7 +3224,48 @@ function changeDependenciesStateTo0(derivation) {
|
|
|
3028
3224
|
obs[i].lowestObserverState = exports.IDerivationState.UP_TO_DATE;
|
|
3029
3225
|
}
|
|
3030
3226
|
|
|
3031
|
-
|
|
3227
|
+
function log(msg) {
|
|
3228
|
+
console.log(msg);
|
|
3229
|
+
return msg;
|
|
3230
|
+
}
|
|
3231
|
+
function whyRun(thing, prop) {
|
|
3232
|
+
deprecated("`whyRun` is deprecated in favor of `trace`");
|
|
3233
|
+
thing = getAtomFromArgs(arguments);
|
|
3234
|
+
if (!thing)
|
|
3235
|
+
return log(getMessage("m024"));
|
|
3236
|
+
if (isComputedValue(thing) || isReaction(thing))
|
|
3237
|
+
return log(thing.whyRun());
|
|
3238
|
+
return fail(getMessage("m025"));
|
|
3239
|
+
}
|
|
3240
|
+
function trace() {
|
|
3241
|
+
var args = [];
|
|
3242
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3243
|
+
args[_i] = arguments[_i];
|
|
3244
|
+
}
|
|
3245
|
+
var enterBreakPoint = false;
|
|
3246
|
+
if (typeof args[args.length - 1] === "boolean")
|
|
3247
|
+
enterBreakPoint = args.pop();
|
|
3248
|
+
var derivation = getAtomFromArgs(args);
|
|
3249
|
+
if (!derivation) {
|
|
3250
|
+
return fail("'trace(break?)' can only be used inside a tracked computed value or a Reaction. Consider passing in the computed value or reaction explicitly");
|
|
3251
|
+
}
|
|
3252
|
+
if (derivation.isTracing === TraceMode.NONE) {
|
|
3253
|
+
console.log("[mobx.trace] '" + derivation.name + "' tracing enabled");
|
|
3254
|
+
}
|
|
3255
|
+
derivation.isTracing = enterBreakPoint ? TraceMode.BREAK : TraceMode.LOG;
|
|
3256
|
+
}
|
|
3257
|
+
function getAtomFromArgs(args) {
|
|
3258
|
+
switch (args.length) {
|
|
3259
|
+
case 0:
|
|
3260
|
+
return globalState.trackingDerivation;
|
|
3261
|
+
case 1:
|
|
3262
|
+
return getAtom(args[0]);
|
|
3263
|
+
case 2:
|
|
3264
|
+
return getAtom(args[0], args[1]);
|
|
3265
|
+
}
|
|
3266
|
+
}
|
|
3267
|
+
|
|
3268
|
+
var Reaction = /** @class */ (function () {
|
|
3032
3269
|
function Reaction(name, onInvalidate) {
|
|
3033
3270
|
if (name === void 0) { name = "Reaction@" + getNextId(); }
|
|
3034
3271
|
this.name = name;
|
|
@@ -3044,6 +3281,7 @@ var Reaction = (function () {
|
|
|
3044
3281
|
this._isScheduled = false;
|
|
3045
3282
|
this._isTrackPending = false;
|
|
3046
3283
|
this._isRunning = false;
|
|
3284
|
+
this.isTracing = TraceMode.NONE;
|
|
3047
3285
|
}
|
|
3048
3286
|
Reaction.prototype.onBecomeStale = function () {
|
|
3049
3287
|
this.schedule();
|
|
@@ -3156,6 +3394,10 @@ var Reaction = (function () {
|
|
|
3156
3394
|
? " (... or any observable accessed during the remainder of the current run)"
|
|
3157
3395
|
: "") + "\n\t" + getMessage("m038") + "\n";
|
|
3158
3396
|
};
|
|
3397
|
+
Reaction.prototype.trace = function (enterBreakPoint) {
|
|
3398
|
+
if (enterBreakPoint === void 0) { enterBreakPoint = false; }
|
|
3399
|
+
trace(this, enterBreakPoint);
|
|
3400
|
+
};
|
|
3159
3401
|
return Reaction;
|
|
3160
3402
|
}());
|
|
3161
3403
|
function registerErrorHandler(handler) {
|
|
@@ -3264,68 +3506,6 @@ var computed = function computed(arg1, arg2, arg3) {
|
|
|
3264
3506
|
computed.struct = computedStructDecorator;
|
|
3265
3507
|
computed.equals = createComputedDecorator;
|
|
3266
3508
|
|
|
3267
|
-
function getAtom(thing, property) {
|
|
3268
|
-
if (typeof thing === "object" && thing !== null) {
|
|
3269
|
-
if (isObservableArray(thing)) {
|
|
3270
|
-
invariant(property === undefined, getMessage("m036"));
|
|
3271
|
-
return thing.$mobx.atom;
|
|
3272
|
-
}
|
|
3273
|
-
if (isObservableMap(thing)) {
|
|
3274
|
-
var anyThing = thing;
|
|
3275
|
-
if (property === undefined)
|
|
3276
|
-
return getAtom(anyThing._keys);
|
|
3277
|
-
var observable = anyThing._data[property] || anyThing._hasMap[property];
|
|
3278
|
-
invariant(!!observable, "the entry '" + property + "' does not exist in the observable map '" + getDebugName(thing) + "'");
|
|
3279
|
-
return observable;
|
|
3280
|
-
}
|
|
3281
|
-
// Initializers run lazily when transpiling to babel, so make sure they are run...
|
|
3282
|
-
runLazyInitializers(thing);
|
|
3283
|
-
if (property && !thing.$mobx)
|
|
3284
|
-
thing[property]; // See #1072 // TODO: remove in 4.0
|
|
3285
|
-
if (isObservableObject(thing)) {
|
|
3286
|
-
if (!property)
|
|
3287
|
-
return fail("please specify a property");
|
|
3288
|
-
var observable = thing.$mobx.values[property];
|
|
3289
|
-
invariant(!!observable, "no observable property '" + property + "' found on the observable object '" + getDebugName(thing) + "'");
|
|
3290
|
-
return observable;
|
|
3291
|
-
}
|
|
3292
|
-
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
|
|
3293
|
-
return thing;
|
|
3294
|
-
}
|
|
3295
|
-
}
|
|
3296
|
-
else if (typeof thing === "function") {
|
|
3297
|
-
if (isReaction(thing.$mobx)) {
|
|
3298
|
-
// disposer function
|
|
3299
|
-
return thing.$mobx;
|
|
3300
|
-
}
|
|
3301
|
-
}
|
|
3302
|
-
return fail("Cannot obtain atom from " + thing);
|
|
3303
|
-
}
|
|
3304
|
-
function getAdministration(thing, property) {
|
|
3305
|
-
invariant(thing, "Expecting some object");
|
|
3306
|
-
if (property !== undefined)
|
|
3307
|
-
return getAdministration(getAtom(thing, property));
|
|
3308
|
-
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing))
|
|
3309
|
-
return thing;
|
|
3310
|
-
if (isObservableMap(thing))
|
|
3311
|
-
return thing;
|
|
3312
|
-
// Initializers run lazily when transpiling to babel, so make sure they are run...
|
|
3313
|
-
runLazyInitializers(thing);
|
|
3314
|
-
if (thing.$mobx)
|
|
3315
|
-
return thing.$mobx;
|
|
3316
|
-
invariant(false, "Cannot obtain administration from " + thing);
|
|
3317
|
-
}
|
|
3318
|
-
function getDebugName(thing, property) {
|
|
3319
|
-
var named;
|
|
3320
|
-
if (property !== undefined)
|
|
3321
|
-
named = getAtom(thing, property);
|
|
3322
|
-
else if (isObservableObject(thing) || isObservableMap(thing))
|
|
3323
|
-
named = getAdministration(thing);
|
|
3324
|
-
else
|
|
3325
|
-
named = getAtom(thing); // valid for arrays as well
|
|
3326
|
-
return named.name;
|
|
3327
|
-
}
|
|
3328
|
-
|
|
3329
3509
|
function isComputed(value, property) {
|
|
3330
3510
|
if (value === null || value === undefined)
|
|
3331
3511
|
return false;
|
|
@@ -3438,7 +3618,7 @@ function createTransformer(transformer, onCleanup) {
|
|
|
3438
3618
|
// This construction is used to avoid leaking refs to the objectCache directly
|
|
3439
3619
|
var resetId = globalState.resetId;
|
|
3440
3620
|
// Local transformer class specifically for this transformer
|
|
3441
|
-
var Transformer = (function (_super) {
|
|
3621
|
+
var Transformer = /** @class */ (function (_super) {
|
|
3442
3622
|
__extends(Transformer, _super);
|
|
3443
3623
|
function Transformer(sourceIdentifier, sourceObject) {
|
|
3444
3624
|
var _this = _super.call(this, function () { return transformer(sourceObject); }, undefined, comparer.default, "Transformer-" + transformer.name + "-" + sourceIdentifier, undefined) || this;
|
|
@@ -3482,52 +3662,6 @@ function getMemoizationId(object) {
|
|
|
3482
3662
|
return tid;
|
|
3483
3663
|
}
|
|
3484
3664
|
|
|
3485
|
-
function log(msg) {
|
|
3486
|
-
console.log(msg);
|
|
3487
|
-
return msg;
|
|
3488
|
-
}
|
|
3489
|
-
function whyRun(thing, prop) {
|
|
3490
|
-
switch (arguments.length) {
|
|
3491
|
-
case 0:
|
|
3492
|
-
thing = globalState.trackingDerivation;
|
|
3493
|
-
if (!thing)
|
|
3494
|
-
return log(getMessage("m024"));
|
|
3495
|
-
break;
|
|
3496
|
-
case 2:
|
|
3497
|
-
thing = getAtom(thing, prop);
|
|
3498
|
-
break;
|
|
3499
|
-
}
|
|
3500
|
-
thing = getAtom(thing);
|
|
3501
|
-
if (isComputedValue(thing))
|
|
3502
|
-
return log(thing.whyRun());
|
|
3503
|
-
else if (isReaction(thing))
|
|
3504
|
-
return log(thing.whyRun());
|
|
3505
|
-
return fail(getMessage("m025"));
|
|
3506
|
-
}
|
|
3507
|
-
|
|
3508
|
-
function getDependencyTree(thing, property) {
|
|
3509
|
-
return nodeToDependencyTree(getAtom(thing, property));
|
|
3510
|
-
}
|
|
3511
|
-
function nodeToDependencyTree(node) {
|
|
3512
|
-
var result = {
|
|
3513
|
-
name: node.name
|
|
3514
|
-
};
|
|
3515
|
-
if (node.observing && node.observing.length > 0)
|
|
3516
|
-
result.dependencies = unique(node.observing).map(nodeToDependencyTree);
|
|
3517
|
-
return result;
|
|
3518
|
-
}
|
|
3519
|
-
function getObserverTree(thing, property) {
|
|
3520
|
-
return nodeToObserverTree(getAtom(thing, property));
|
|
3521
|
-
}
|
|
3522
|
-
function nodeToObserverTree(node) {
|
|
3523
|
-
var result = {
|
|
3524
|
-
name: node.name
|
|
3525
|
-
};
|
|
3526
|
-
if (hasObservers(node))
|
|
3527
|
-
result.observers = getObservers(node).map(nodeToObserverTree);
|
|
3528
|
-
return result;
|
|
3529
|
-
}
|
|
3530
|
-
|
|
3531
3665
|
function interceptReads(thing, propOrHandler, handler) {
|
|
3532
3666
|
var target;
|
|
3533
3667
|
if (isObservableMap(thing) || isObservableArray(thing) || isObservableValue(thing)) {
|
|
@@ -3694,4 +3828,5 @@ exports.expr = expr;
|
|
|
3694
3828
|
exports.toJS = toJS;
|
|
3695
3829
|
exports.createTransformer = createTransformer;
|
|
3696
3830
|
exports.whyRun = whyRun;
|
|
3831
|
+
exports.trace = trace;
|
|
3697
3832
|
exports.isArrayLike = isArrayLike;
|