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/dist/mobx.esm.js CHANGED
@@ -263,6 +263,17 @@ var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function get
263
263
  });
264
264
  return res;
265
265
  };
266
+ function getFlag(flags, mask) {
267
+ return !!(flags & mask);
268
+ }
269
+ function setFlag(flags, mask, newValue) {
270
+ if (newValue) {
271
+ flags |= mask;
272
+ } else {
273
+ flags &= ~mask;
274
+ }
275
+ return flags;
276
+ }
266
277
 
267
278
  function _arrayLikeToArray(r, a) {
268
279
  (null == a || a > r.length) && (a = r.length);
@@ -415,11 +426,8 @@ var Atom = /*#__PURE__*/function () {
415
426
  name_ = process.env.NODE_ENV !== "production" ? "Atom@" + getNextId() : "Atom";
416
427
  }
417
428
  this.name_ = void 0;
418
- this.isPendingUnobservation = false;
419
- // for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
420
- this.isBeingObserved = false;
429
+ this.flags_ = 0;
421
430
  this.observers_ = new Set();
422
- this.diffValue_ = 0;
423
431
  this.lastAccessedBy_ = 0;
424
432
  this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
425
433
  // onBecomeObservedListeners
@@ -428,6 +436,7 @@ var Atom = /*#__PURE__*/function () {
428
436
  this.onBUOL = void 0;
429
437
  this.name_ = name_;
430
438
  }
439
+ // for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
431
440
  var _proto = Atom.prototype;
432
441
  _proto.onBO = function onBO() {
433
442
  if (this.onBOL) {
@@ -461,8 +470,35 @@ var Atom = /*#__PURE__*/function () {
461
470
  _proto.toString = function toString() {
462
471
  return this.name_;
463
472
  };
464
- return Atom;
473
+ return _createClass(Atom, [{
474
+ key: "isBeingObserved",
475
+ get: function get() {
476
+ return getFlag(this.flags_, Atom.isBeingObservedMask_);
477
+ },
478
+ set: function set(newValue) {
479
+ this.flags_ = setFlag(this.flags_, Atom.isBeingObservedMask_, newValue);
480
+ }
481
+ }, {
482
+ key: "isPendingUnobservation",
483
+ get: function get() {
484
+ return getFlag(this.flags_, Atom.isPendingUnobservationMask_);
485
+ },
486
+ set: function set(newValue) {
487
+ this.flags_ = setFlag(this.flags_, Atom.isPendingUnobservationMask_, newValue);
488
+ }
489
+ }, {
490
+ key: "diffValue",
491
+ get: function get() {
492
+ return getFlag(this.flags_, Atom.diffValueMask_) ? 1 : 0;
493
+ },
494
+ set: function set(newValue) {
495
+ this.flags_ = setFlag(this.flags_, Atom.diffValueMask_, newValue === 1 ? true : false);
496
+ }
497
+ }]);
465
498
  }();
499
+ Atom.isBeingObservedMask_ = 1;
500
+ Atom.isPendingUnobservationMask_ = 2;
501
+ Atom.diffValueMask_ = 4;
466
502
  var isAtom = /*#__PURE__*/createInstanceofPredicate("Atom", Atom);
467
503
  function createAtom(name, onBecomeObservedHandler, onBecomeUnobservedHandler) {
468
504
  if (onBecomeObservedHandler === void 0) {
@@ -1430,17 +1466,6 @@ var ObservableValue = /*#__PURE__*/function (_Atom) {
1430
1466
  }(Atom);
1431
1467
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1432
1468
 
1433
- function getFlag(flags, mask) {
1434
- return !!(flags & mask);
1435
- }
1436
- function setFlag(flags, mask, newValue) {
1437
- if (newValue) {
1438
- flags |= mask;
1439
- } else {
1440
- flags &= ~mask;
1441
- }
1442
- return flags;
1443
- }
1444
1469
  /**
1445
1470
  * A node in the state dependency root that observes other nodes, and can be observed itself.
1446
1471
  *
@@ -1480,7 +1505,6 @@ var ComputedValue = /*#__PURE__*/function () {
1480
1505
  this.newObserving_ = null;
1481
1506
  // during tracking it's an array with new observed observers
1482
1507
  this.observers_ = new Set();
1483
- this.diffValue_ = 0;
1484
1508
  this.runId_ = 0;
1485
1509
  this.lastAccessedBy_ = 0;
1486
1510
  this.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
@@ -1710,12 +1734,21 @@ var ComputedValue = /*#__PURE__*/function () {
1710
1734
  set: function set(newValue) {
1711
1735
  this.flags_ = setFlag(this.flags_, ComputedValue.isPendingUnobservationMask_, newValue);
1712
1736
  }
1737
+ }, {
1738
+ key: "diffValue",
1739
+ get: function get() {
1740
+ return getFlag(this.flags_, ComputedValue.diffValueMask_) ? 1 : 0;
1741
+ },
1742
+ set: function set(newValue) {
1743
+ this.flags_ = setFlag(this.flags_, ComputedValue.diffValueMask_, newValue === 1 ? true : false);
1744
+ }
1713
1745
  }]);
1714
1746
  }();
1715
1747
  ComputedValue.isComputingMask_ = 1;
1716
1748
  ComputedValue.isRunningSetterMask_ = 2;
1717
1749
  ComputedValue.isBeingObservedMask_ = 4;
1718
1750
  ComputedValue.isPendingUnobservationMask_ = 8;
1751
+ ComputedValue.diffValueMask_ = 16;
1719
1752
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1720
1753
 
1721
1754
  var IDerivationState_;
@@ -1890,8 +1923,8 @@ function bindDependencies(derivation) {
1890
1923
  l = derivation.unboundDepsCount_;
1891
1924
  for (var i = 0; i < l; i++) {
1892
1925
  var dep = observing[i];
1893
- if (dep.diffValue_ === 0) {
1894
- dep.diffValue_ = 1;
1926
+ if (dep.diffValue === 0) {
1927
+ dep.diffValue = 1;
1895
1928
  if (i0 !== i) {
1896
1929
  observing[i0] = dep;
1897
1930
  }
@@ -1911,18 +1944,18 @@ function bindDependencies(derivation) {
1911
1944
  l = prevObserving.length;
1912
1945
  while (l--) {
1913
1946
  var _dep = prevObserving[l];
1914
- if (_dep.diffValue_ === 0) {
1947
+ if (_dep.diffValue === 0) {
1915
1948
  removeObserver(_dep, derivation);
1916
1949
  }
1917
- _dep.diffValue_ = 0;
1950
+ _dep.diffValue = 0;
1918
1951
  }
1919
1952
  // Go through all new observables and check diffValue: (now it should be unique)
1920
1953
  // 0: it was set to 0 in last loop. don't need to do anything.
1921
1954
  // 1: it wasn't observed, let's observe it. set back to 0
1922
1955
  while (i0--) {
1923
1956
  var _dep2 = observing[i0];
1924
- if (_dep2.diffValue_ === 1) {
1925
- _dep2.diffValue_ = 0;
1957
+ if (_dep2.diffValue === 1) {
1958
+ _dep2.diffValue = 0;
1926
1959
  addObserver(_dep2, derivation);
1927
1960
  }
1928
1961
  }
@@ -2375,13 +2408,9 @@ var Reaction = /*#__PURE__*/function () {
2375
2408
  // nodes we are looking at. Our value depends on these nodes
2376
2409
  this.newObserving_ = [];
2377
2410
  this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
2378
- this.diffValue_ = 0;
2379
2411
  this.runId_ = 0;
2380
2412
  this.unboundDepsCount_ = 0;
2381
- this.isDisposed_ = false;
2382
- this.isScheduled_ = false;
2383
- this.isTrackPending_ = false;
2384
- this.isRunning_ = false;
2413
+ this.flags_ = 0;
2385
2414
  this.isTracing_ = TraceMode.NONE;
2386
2415
  this.name_ = name_;
2387
2416
  this.onInvalidate_ = onInvalidate_;
@@ -2393,29 +2422,26 @@ var Reaction = /*#__PURE__*/function () {
2393
2422
  this.schedule_();
2394
2423
  };
2395
2424
  _proto.schedule_ = function schedule_() {
2396
- if (!this.isScheduled_) {
2397
- this.isScheduled_ = true;
2425
+ if (!this.isScheduled) {
2426
+ this.isScheduled = true;
2398
2427
  globalState.pendingReactions.push(this);
2399
2428
  runReactions();
2400
2429
  }
2401
- };
2402
- _proto.isScheduled = function isScheduled() {
2403
- return this.isScheduled_;
2404
2430
  }
2405
2431
  /**
2406
2432
  * internal, use schedule() if you intend to kick off a reaction
2407
2433
  */;
2408
2434
  _proto.runReaction_ = function runReaction_() {
2409
- if (!this.isDisposed_) {
2435
+ if (!this.isDisposed) {
2410
2436
  startBatch();
2411
- this.isScheduled_ = false;
2437
+ this.isScheduled = false;
2412
2438
  var prev = globalState.trackingContext;
2413
2439
  globalState.trackingContext = this;
2414
2440
  if (shouldCompute(this)) {
2415
- this.isTrackPending_ = true;
2441
+ this.isTrackPending = true;
2416
2442
  try {
2417
2443
  this.onInvalidate_();
2418
- if (process.env.NODE_ENV !== "production" && this.isTrackPending_ && isSpyEnabled()) {
2444
+ if (process.env.NODE_ENV !== "production" && this.isTrackPending && isSpyEnabled()) {
2419
2445
  // onInvalidate didn't trigger track right away..
2420
2446
  spyReport({
2421
2447
  name: this.name_,
@@ -2431,7 +2457,7 @@ var Reaction = /*#__PURE__*/function () {
2431
2457
  }
2432
2458
  };
2433
2459
  _proto.track = function track(fn) {
2434
- if (this.isDisposed_) {
2460
+ if (this.isDisposed) {
2435
2461
  return;
2436
2462
  // console.warn("Reaction already disposed") // Note: Not a warning / error in mobx 4 either
2437
2463
  }
@@ -2445,14 +2471,14 @@ var Reaction = /*#__PURE__*/function () {
2445
2471
  type: "reaction"
2446
2472
  });
2447
2473
  }
2448
- this.isRunning_ = true;
2474
+ this.isRunning = true;
2449
2475
  var prevReaction = globalState.trackingContext; // reactions could create reactions...
2450
2476
  globalState.trackingContext = this;
2451
2477
  var result = trackDerivedFunction(this, fn, undefined);
2452
2478
  globalState.trackingContext = prevReaction;
2453
- this.isRunning_ = false;
2454
- this.isTrackPending_ = false;
2455
- if (this.isDisposed_) {
2479
+ this.isRunning = false;
2480
+ this.isTrackPending = false;
2481
+ if (this.isDisposed) {
2456
2482
  // disposed during last run. Clean up everything that was bound after the dispose call.
2457
2483
  clearObserving(this);
2458
2484
  }
@@ -2495,9 +2521,9 @@ var Reaction = /*#__PURE__*/function () {
2495
2521
  });
2496
2522
  };
2497
2523
  _proto.dispose = function dispose() {
2498
- if (!this.isDisposed_) {
2499
- this.isDisposed_ = true;
2500
- if (!this.isRunning_) {
2524
+ if (!this.isDisposed) {
2525
+ this.isDisposed = true;
2526
+ if (!this.isRunning) {
2501
2527
  // if disposed while running, clean up later. Maybe not optimal, but rare case
2502
2528
  startBatch();
2503
2529
  clearObserving(this);
@@ -2524,8 +2550,53 @@ var Reaction = /*#__PURE__*/function () {
2524
2550
  }
2525
2551
  trace(this, enterBreakPoint);
2526
2552
  };
2527
- return Reaction;
2553
+ return _createClass(Reaction, [{
2554
+ key: "isDisposed",
2555
+ get: function get() {
2556
+ return getFlag(this.flags_, Reaction.isDisposedMask_);
2557
+ },
2558
+ set: function set(newValue) {
2559
+ this.flags_ = setFlag(this.flags_, Reaction.isDisposedMask_, newValue);
2560
+ }
2561
+ }, {
2562
+ key: "isScheduled",
2563
+ get: function get() {
2564
+ return getFlag(this.flags_, Reaction.isScheduledMask_);
2565
+ },
2566
+ set: function set(newValue) {
2567
+ this.flags_ = setFlag(this.flags_, Reaction.isScheduledMask_, newValue);
2568
+ }
2569
+ }, {
2570
+ key: "isTrackPending",
2571
+ get: function get() {
2572
+ return getFlag(this.flags_, Reaction.isTrackPendingMask_);
2573
+ },
2574
+ set: function set(newValue) {
2575
+ this.flags_ = setFlag(this.flags_, Reaction.isTrackPendingMask_, newValue);
2576
+ }
2577
+ }, {
2578
+ key: "isRunning",
2579
+ get: function get() {
2580
+ return getFlag(this.flags_, Reaction.isRunningMask_);
2581
+ },
2582
+ set: function set(newValue) {
2583
+ this.flags_ = setFlag(this.flags_, Reaction.isRunningMask_, newValue);
2584
+ }
2585
+ }, {
2586
+ key: "diffValue",
2587
+ get: function get() {
2588
+ return getFlag(this.flags_, Reaction.diffValueMask_) ? 1 : 0;
2589
+ },
2590
+ set: function set(newValue) {
2591
+ this.flags_ = setFlag(this.flags_, Reaction.diffValueMask_, newValue === 1 ? true : false);
2592
+ }
2593
+ }]);
2528
2594
  }();
2595
+ Reaction.isDisposedMask_ = 1;
2596
+ Reaction.isScheduledMask_ = 2;
2597
+ Reaction.isTrackPendingMask_ = 4;
2598
+ Reaction.isRunningMask_ = 8;
2599
+ Reaction.diffValueMask_ = 16;
2529
2600
  function onReactionError(handler) {
2530
2601
  globalState.globalReactionErrorHandlers.push(handler);
2531
2602
  return function () {
@@ -2731,7 +2802,7 @@ function autorun(view, opts) {
2731
2802
  isScheduled = true;
2732
2803
  scheduler(function () {
2733
2804
  isScheduled = false;
2734
- if (!reaction.isDisposed_) {
2805
+ if (!reaction.isDisposed) {
2735
2806
  reaction.track(reactionRunner);
2736
2807
  }
2737
2808
  });
@@ -2785,7 +2856,7 @@ function reaction(expression, effect, opts) {
2785
2856
  }, opts.onError, opts.requiresObservable);
2786
2857
  function reactionRunner() {
2787
2858
  isScheduled = false;
2788
- if (r.isDisposed_) {
2859
+ if (r.isDisposed) {
2789
2860
  return;
2790
2861
  }
2791
2862
  var changed = false;
@@ -3415,7 +3486,7 @@ function _when(predicate, effect, opts) {
3415
3486
  if (typeof opts.timeout === "number") {
3416
3487
  var error = new Error("WHEN_TIMEOUT");
3417
3488
  timeoutHandle = setTimeout(function () {
3418
- if (!disposer[$mobx].isDisposed_) {
3489
+ if (!disposer[$mobx].isDisposed) {
3419
3490
  disposer();
3420
3491
  if (opts.onError) {
3421
3492
  opts.onError(error);