mobx 6.13.0 → 6.13.1
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 +6 -0
- package/dist/core/atom.d.ts +10 -3
- package/dist/core/computedvalue.d.ts +3 -1
- package/dist/core/observable.d.ts +1 -1
- package/dist/core/reaction.d.ts +16 -6
- package/dist/mobx.cjs.development.js +120 -49
- package/dist/mobx.cjs.development.js.map +1 -1
- package/dist/mobx.cjs.production.min.js +1 -1
- package/dist/mobx.cjs.production.min.js.map +1 -1
- package/dist/mobx.esm.development.js +120 -49
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +120 -49
- package/dist/mobx.esm.js.map +1 -1
- package/dist/mobx.esm.production.min.js +1 -1
- package/dist/mobx.esm.production.min.js.map +1 -1
- package/dist/mobx.umd.development.js +120 -49
- package/dist/mobx.umd.development.js.map +1 -1
- package/dist/mobx.umd.production.min.js +1 -1
- package/dist/mobx.umd.production.min.js.map +1 -1
- package/dist/utils/utils.d.ts +2 -0
- package/package.json +1 -1
- package/src/api/autorun.ts +4 -4
- package/src/api/when.ts +1 -1
- package/src/core/atom.ts +29 -3
- package/src/core/computedvalue.ts +19 -18
- package/src/core/derivation.ts +6 -6
- package/src/core/observable.ts +1 -1
- package/src/core/reaction.ts +59 -23
- package/src/utils/utils.ts +13 -0
|
@@ -262,6 +262,17 @@ var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function get
|
|
|
262
262
|
});
|
|
263
263
|
return res;
|
|
264
264
|
};
|
|
265
|
+
function getFlag(flags, mask) {
|
|
266
|
+
return !!(flags & mask);
|
|
267
|
+
}
|
|
268
|
+
function setFlag(flags, mask, newValue) {
|
|
269
|
+
if (newValue) {
|
|
270
|
+
flags |= mask;
|
|
271
|
+
} else {
|
|
272
|
+
flags &= ~mask;
|
|
273
|
+
}
|
|
274
|
+
return flags;
|
|
275
|
+
}
|
|
265
276
|
|
|
266
277
|
function _arrayLikeToArray(r, a) {
|
|
267
278
|
(null == a || a > r.length) && (a = r.length);
|
|
@@ -414,11 +425,8 @@ var Atom = /*#__PURE__*/function () {
|
|
|
414
425
|
name_ = "Atom@" + getNextId() ;
|
|
415
426
|
}
|
|
416
427
|
this.name_ = void 0;
|
|
417
|
-
this.
|
|
418
|
-
// for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
|
|
419
|
-
this.isBeingObserved = false;
|
|
428
|
+
this.flags_ = 0;
|
|
420
429
|
this.observers_ = new Set();
|
|
421
|
-
this.diffValue_ = 0;
|
|
422
430
|
this.lastAccessedBy_ = 0;
|
|
423
431
|
this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
|
|
424
432
|
// onBecomeObservedListeners
|
|
@@ -427,6 +435,7 @@ var Atom = /*#__PURE__*/function () {
|
|
|
427
435
|
this.onBUOL = void 0;
|
|
428
436
|
this.name_ = name_;
|
|
429
437
|
}
|
|
438
|
+
// for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
|
|
430
439
|
var _proto = Atom.prototype;
|
|
431
440
|
_proto.onBO = function onBO() {
|
|
432
441
|
if (this.onBOL) {
|
|
@@ -460,8 +469,35 @@ var Atom = /*#__PURE__*/function () {
|
|
|
460
469
|
_proto.toString = function toString() {
|
|
461
470
|
return this.name_;
|
|
462
471
|
};
|
|
463
|
-
return Atom
|
|
472
|
+
return _createClass(Atom, [{
|
|
473
|
+
key: "isBeingObserved",
|
|
474
|
+
get: function get() {
|
|
475
|
+
return getFlag(this.flags_, Atom.isBeingObservedMask_);
|
|
476
|
+
},
|
|
477
|
+
set: function set(newValue) {
|
|
478
|
+
this.flags_ = setFlag(this.flags_, Atom.isBeingObservedMask_, newValue);
|
|
479
|
+
}
|
|
480
|
+
}, {
|
|
481
|
+
key: "isPendingUnobservation",
|
|
482
|
+
get: function get() {
|
|
483
|
+
return getFlag(this.flags_, Atom.isPendingUnobservationMask_);
|
|
484
|
+
},
|
|
485
|
+
set: function set(newValue) {
|
|
486
|
+
this.flags_ = setFlag(this.flags_, Atom.isPendingUnobservationMask_, newValue);
|
|
487
|
+
}
|
|
488
|
+
}, {
|
|
489
|
+
key: "diffValue",
|
|
490
|
+
get: function get() {
|
|
491
|
+
return getFlag(this.flags_, Atom.diffValueMask_) ? 1 : 0;
|
|
492
|
+
},
|
|
493
|
+
set: function set(newValue) {
|
|
494
|
+
this.flags_ = setFlag(this.flags_, Atom.diffValueMask_, newValue === 1 ? true : false);
|
|
495
|
+
}
|
|
496
|
+
}]);
|
|
464
497
|
}();
|
|
498
|
+
Atom.isBeingObservedMask_ = 1;
|
|
499
|
+
Atom.isPendingUnobservationMask_ = 2;
|
|
500
|
+
Atom.diffValueMask_ = 4;
|
|
465
501
|
var isAtom = /*#__PURE__*/createInstanceofPredicate("Atom", Atom);
|
|
466
502
|
function createAtom(name, onBecomeObservedHandler, onBecomeUnobservedHandler) {
|
|
467
503
|
if (onBecomeObservedHandler === void 0) {
|
|
@@ -1429,17 +1465,6 @@ var ObservableValue = /*#__PURE__*/function (_Atom) {
|
|
|
1429
1465
|
}(Atom);
|
|
1430
1466
|
var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
|
|
1431
1467
|
|
|
1432
|
-
function getFlag(flags, mask) {
|
|
1433
|
-
return !!(flags & mask);
|
|
1434
|
-
}
|
|
1435
|
-
function setFlag(flags, mask, newValue) {
|
|
1436
|
-
if (newValue) {
|
|
1437
|
-
flags |= mask;
|
|
1438
|
-
} else {
|
|
1439
|
-
flags &= ~mask;
|
|
1440
|
-
}
|
|
1441
|
-
return flags;
|
|
1442
|
-
}
|
|
1443
1468
|
/**
|
|
1444
1469
|
* A node in the state dependency root that observes other nodes, and can be observed itself.
|
|
1445
1470
|
*
|
|
@@ -1479,7 +1504,6 @@ var ComputedValue = /*#__PURE__*/function () {
|
|
|
1479
1504
|
this.newObserving_ = null;
|
|
1480
1505
|
// during tracking it's an array with new observed observers
|
|
1481
1506
|
this.observers_ = new Set();
|
|
1482
|
-
this.diffValue_ = 0;
|
|
1483
1507
|
this.runId_ = 0;
|
|
1484
1508
|
this.lastAccessedBy_ = 0;
|
|
1485
1509
|
this.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
|
|
@@ -1706,12 +1730,21 @@ var ComputedValue = /*#__PURE__*/function () {
|
|
|
1706
1730
|
set: function set(newValue) {
|
|
1707
1731
|
this.flags_ = setFlag(this.flags_, ComputedValue.isPendingUnobservationMask_, newValue);
|
|
1708
1732
|
}
|
|
1733
|
+
}, {
|
|
1734
|
+
key: "diffValue",
|
|
1735
|
+
get: function get() {
|
|
1736
|
+
return getFlag(this.flags_, ComputedValue.diffValueMask_) ? 1 : 0;
|
|
1737
|
+
},
|
|
1738
|
+
set: function set(newValue) {
|
|
1739
|
+
this.flags_ = setFlag(this.flags_, ComputedValue.diffValueMask_, newValue === 1 ? true : false);
|
|
1740
|
+
}
|
|
1709
1741
|
}]);
|
|
1710
1742
|
}();
|
|
1711
1743
|
ComputedValue.isComputingMask_ = 1;
|
|
1712
1744
|
ComputedValue.isRunningSetterMask_ = 2;
|
|
1713
1745
|
ComputedValue.isBeingObservedMask_ = 4;
|
|
1714
1746
|
ComputedValue.isPendingUnobservationMask_ = 8;
|
|
1747
|
+
ComputedValue.diffValueMask_ = 16;
|
|
1715
1748
|
var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
|
|
1716
1749
|
|
|
1717
1750
|
var IDerivationState_;
|
|
@@ -1880,8 +1913,8 @@ function bindDependencies(derivation) {
|
|
|
1880
1913
|
l = derivation.unboundDepsCount_;
|
|
1881
1914
|
for (var i = 0; i < l; i++) {
|
|
1882
1915
|
var dep = observing[i];
|
|
1883
|
-
if (dep.
|
|
1884
|
-
dep.
|
|
1916
|
+
if (dep.diffValue === 0) {
|
|
1917
|
+
dep.diffValue = 1;
|
|
1885
1918
|
if (i0 !== i) {
|
|
1886
1919
|
observing[i0] = dep;
|
|
1887
1920
|
}
|
|
@@ -1901,18 +1934,18 @@ function bindDependencies(derivation) {
|
|
|
1901
1934
|
l = prevObserving.length;
|
|
1902
1935
|
while (l--) {
|
|
1903
1936
|
var _dep = prevObserving[l];
|
|
1904
|
-
if (_dep.
|
|
1937
|
+
if (_dep.diffValue === 0) {
|
|
1905
1938
|
removeObserver(_dep, derivation);
|
|
1906
1939
|
}
|
|
1907
|
-
_dep.
|
|
1940
|
+
_dep.diffValue = 0;
|
|
1908
1941
|
}
|
|
1909
1942
|
// Go through all new observables and check diffValue: (now it should be unique)
|
|
1910
1943
|
// 0: it was set to 0 in last loop. don't need to do anything.
|
|
1911
1944
|
// 1: it wasn't observed, let's observe it. set back to 0
|
|
1912
1945
|
while (i0--) {
|
|
1913
1946
|
var _dep2 = observing[i0];
|
|
1914
|
-
if (_dep2.
|
|
1915
|
-
_dep2.
|
|
1947
|
+
if (_dep2.diffValue === 1) {
|
|
1948
|
+
_dep2.diffValue = 0;
|
|
1916
1949
|
addObserver(_dep2, derivation);
|
|
1917
1950
|
}
|
|
1918
1951
|
}
|
|
@@ -2365,13 +2398,9 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2365
2398
|
// nodes we are looking at. Our value depends on these nodes
|
|
2366
2399
|
this.newObserving_ = [];
|
|
2367
2400
|
this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
|
|
2368
|
-
this.diffValue_ = 0;
|
|
2369
2401
|
this.runId_ = 0;
|
|
2370
2402
|
this.unboundDepsCount_ = 0;
|
|
2371
|
-
this.
|
|
2372
|
-
this.isScheduled_ = false;
|
|
2373
|
-
this.isTrackPending_ = false;
|
|
2374
|
-
this.isRunning_ = false;
|
|
2403
|
+
this.flags_ = 0;
|
|
2375
2404
|
this.isTracing_ = TraceMode.NONE;
|
|
2376
2405
|
this.name_ = name_;
|
|
2377
2406
|
this.onInvalidate_ = onInvalidate_;
|
|
@@ -2383,29 +2412,26 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2383
2412
|
this.schedule_();
|
|
2384
2413
|
};
|
|
2385
2414
|
_proto.schedule_ = function schedule_() {
|
|
2386
|
-
if (!this.
|
|
2387
|
-
this.
|
|
2415
|
+
if (!this.isScheduled) {
|
|
2416
|
+
this.isScheduled = true;
|
|
2388
2417
|
globalState.pendingReactions.push(this);
|
|
2389
2418
|
runReactions();
|
|
2390
2419
|
}
|
|
2391
|
-
};
|
|
2392
|
-
_proto.isScheduled = function isScheduled() {
|
|
2393
|
-
return this.isScheduled_;
|
|
2394
2420
|
}
|
|
2395
2421
|
/**
|
|
2396
2422
|
* internal, use schedule() if you intend to kick off a reaction
|
|
2397
2423
|
*/;
|
|
2398
2424
|
_proto.runReaction_ = function runReaction_() {
|
|
2399
|
-
if (!this.
|
|
2425
|
+
if (!this.isDisposed) {
|
|
2400
2426
|
startBatch();
|
|
2401
|
-
this.
|
|
2427
|
+
this.isScheduled = false;
|
|
2402
2428
|
var prev = globalState.trackingContext;
|
|
2403
2429
|
globalState.trackingContext = this;
|
|
2404
2430
|
if (shouldCompute(this)) {
|
|
2405
|
-
this.
|
|
2431
|
+
this.isTrackPending = true;
|
|
2406
2432
|
try {
|
|
2407
2433
|
this.onInvalidate_();
|
|
2408
|
-
if ("development" !== "production" && this.
|
|
2434
|
+
if ("development" !== "production" && this.isTrackPending && isSpyEnabled()) {
|
|
2409
2435
|
// onInvalidate didn't trigger track right away..
|
|
2410
2436
|
spyReport({
|
|
2411
2437
|
name: this.name_,
|
|
@@ -2421,7 +2447,7 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2421
2447
|
}
|
|
2422
2448
|
};
|
|
2423
2449
|
_proto.track = function track(fn) {
|
|
2424
|
-
if (this.
|
|
2450
|
+
if (this.isDisposed) {
|
|
2425
2451
|
return;
|
|
2426
2452
|
// console.warn("Reaction already disposed") // Note: Not a warning / error in mobx 4 either
|
|
2427
2453
|
}
|
|
@@ -2435,14 +2461,14 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2435
2461
|
type: "reaction"
|
|
2436
2462
|
});
|
|
2437
2463
|
}
|
|
2438
|
-
this.
|
|
2464
|
+
this.isRunning = true;
|
|
2439
2465
|
var prevReaction = globalState.trackingContext; // reactions could create reactions...
|
|
2440
2466
|
globalState.trackingContext = this;
|
|
2441
2467
|
var result = trackDerivedFunction(this, fn, undefined);
|
|
2442
2468
|
globalState.trackingContext = prevReaction;
|
|
2443
|
-
this.
|
|
2444
|
-
this.
|
|
2445
|
-
if (this.
|
|
2469
|
+
this.isRunning = false;
|
|
2470
|
+
this.isTrackPending = false;
|
|
2471
|
+
if (this.isDisposed) {
|
|
2446
2472
|
// disposed during last run. Clean up everything that was bound after the dispose call.
|
|
2447
2473
|
clearObserving(this);
|
|
2448
2474
|
}
|
|
@@ -2485,9 +2511,9 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2485
2511
|
});
|
|
2486
2512
|
};
|
|
2487
2513
|
_proto.dispose = function dispose() {
|
|
2488
|
-
if (!this.
|
|
2489
|
-
this.
|
|
2490
|
-
if (!this.
|
|
2514
|
+
if (!this.isDisposed) {
|
|
2515
|
+
this.isDisposed = true;
|
|
2516
|
+
if (!this.isRunning) {
|
|
2491
2517
|
// if disposed while running, clean up later. Maybe not optimal, but rare case
|
|
2492
2518
|
startBatch();
|
|
2493
2519
|
clearObserving(this);
|
|
@@ -2514,8 +2540,53 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2514
2540
|
}
|
|
2515
2541
|
trace(this, enterBreakPoint);
|
|
2516
2542
|
};
|
|
2517
|
-
return Reaction
|
|
2543
|
+
return _createClass(Reaction, [{
|
|
2544
|
+
key: "isDisposed",
|
|
2545
|
+
get: function get() {
|
|
2546
|
+
return getFlag(this.flags_, Reaction.isDisposedMask_);
|
|
2547
|
+
},
|
|
2548
|
+
set: function set(newValue) {
|
|
2549
|
+
this.flags_ = setFlag(this.flags_, Reaction.isDisposedMask_, newValue);
|
|
2550
|
+
}
|
|
2551
|
+
}, {
|
|
2552
|
+
key: "isScheduled",
|
|
2553
|
+
get: function get() {
|
|
2554
|
+
return getFlag(this.flags_, Reaction.isScheduledMask_);
|
|
2555
|
+
},
|
|
2556
|
+
set: function set(newValue) {
|
|
2557
|
+
this.flags_ = setFlag(this.flags_, Reaction.isScheduledMask_, newValue);
|
|
2558
|
+
}
|
|
2559
|
+
}, {
|
|
2560
|
+
key: "isTrackPending",
|
|
2561
|
+
get: function get() {
|
|
2562
|
+
return getFlag(this.flags_, Reaction.isTrackPendingMask_);
|
|
2563
|
+
},
|
|
2564
|
+
set: function set(newValue) {
|
|
2565
|
+
this.flags_ = setFlag(this.flags_, Reaction.isTrackPendingMask_, newValue);
|
|
2566
|
+
}
|
|
2567
|
+
}, {
|
|
2568
|
+
key: "isRunning",
|
|
2569
|
+
get: function get() {
|
|
2570
|
+
return getFlag(this.flags_, Reaction.isRunningMask_);
|
|
2571
|
+
},
|
|
2572
|
+
set: function set(newValue) {
|
|
2573
|
+
this.flags_ = setFlag(this.flags_, Reaction.isRunningMask_, newValue);
|
|
2574
|
+
}
|
|
2575
|
+
}, {
|
|
2576
|
+
key: "diffValue",
|
|
2577
|
+
get: function get() {
|
|
2578
|
+
return getFlag(this.flags_, Reaction.diffValueMask_) ? 1 : 0;
|
|
2579
|
+
},
|
|
2580
|
+
set: function set(newValue) {
|
|
2581
|
+
this.flags_ = setFlag(this.flags_, Reaction.diffValueMask_, newValue === 1 ? true : false);
|
|
2582
|
+
}
|
|
2583
|
+
}]);
|
|
2518
2584
|
}();
|
|
2585
|
+
Reaction.isDisposedMask_ = 1;
|
|
2586
|
+
Reaction.isScheduledMask_ = 2;
|
|
2587
|
+
Reaction.isTrackPendingMask_ = 4;
|
|
2588
|
+
Reaction.isRunningMask_ = 8;
|
|
2589
|
+
Reaction.diffValueMask_ = 16;
|
|
2519
2590
|
function onReactionError(handler) {
|
|
2520
2591
|
globalState.globalReactionErrorHandlers.push(handler);
|
|
2521
2592
|
return function () {
|
|
@@ -2709,7 +2780,7 @@ function autorun(view, opts) {
|
|
|
2709
2780
|
isScheduled = true;
|
|
2710
2781
|
scheduler(function () {
|
|
2711
2782
|
isScheduled = false;
|
|
2712
|
-
if (!reaction.
|
|
2783
|
+
if (!reaction.isDisposed) {
|
|
2713
2784
|
reaction.track(reactionRunner);
|
|
2714
2785
|
}
|
|
2715
2786
|
});
|
|
@@ -2763,7 +2834,7 @@ function reaction(expression, effect, opts) {
|
|
|
2763
2834
|
}, opts.onError, opts.requiresObservable);
|
|
2764
2835
|
function reactionRunner() {
|
|
2765
2836
|
isScheduled = false;
|
|
2766
|
-
if (r.
|
|
2837
|
+
if (r.isDisposed) {
|
|
2767
2838
|
return;
|
|
2768
2839
|
}
|
|
2769
2840
|
var changed = false;
|
|
@@ -3390,7 +3461,7 @@ function _when(predicate, effect, opts) {
|
|
|
3390
3461
|
if (typeof opts.timeout === "number") {
|
|
3391
3462
|
var error = new Error("WHEN_TIMEOUT");
|
|
3392
3463
|
timeoutHandle = setTimeout(function () {
|
|
3393
|
-
if (!disposer[$mobx].
|
|
3464
|
+
if (!disposer[$mobx].isDisposed) {
|
|
3394
3465
|
disposer();
|
|
3395
3466
|
if (opts.onError) {
|
|
3396
3467
|
opts.onError(error);
|