mobx 6.12.3 → 6.12.4

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
@@ -434,8 +434,8 @@ var Atom = /*#__PURE__*/function () {
434
434
  name_ = process.env.NODE_ENV !== "production" ? "Atom@" + getNextId() : "Atom";
435
435
  }
436
436
  this.name_ = void 0;
437
- this.isPendingUnobservation_ = false;
438
- this.isBeingObserved_ = false;
437
+ this.isPendingUnobservation = false;
438
+ this.isBeingObserved = false;
439
439
  this.observers_ = new Set();
440
440
  this.diffValue_ = 0;
441
441
  this.lastAccessedBy_ = 0;
@@ -1458,6 +1458,17 @@ var ObservableValue = /*#__PURE__*/function (_Atom) {
1458
1458
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1459
1459
 
1460
1460
  var _Symbol$toPrimitive$1;
1461
+ function getFlag(flags, mask) {
1462
+ return !!(flags & mask);
1463
+ }
1464
+ function setFlag(flags, mask, newValue) {
1465
+ if (newValue) {
1466
+ flags |= mask;
1467
+ } else {
1468
+ flags &= ~mask;
1469
+ }
1470
+ return flags;
1471
+ }
1461
1472
  /**
1462
1473
  * A node in the state dependency root that observes other nodes, and can be observed itself.
1463
1474
  *
@@ -1482,8 +1493,6 @@ var ComputedValue = /*#__PURE__*/function () {
1482
1493
  // nodes we are looking at. Our value depends on these nodes
1483
1494
  // during tracking it's an array with new observed observers
1484
1495
 
1485
- // to check for cycles
1486
-
1487
1496
  // N.B: unminified as it is used by MST
1488
1497
 
1489
1498
  /**
@@ -1502,8 +1511,6 @@ var ComputedValue = /*#__PURE__*/function () {
1502
1511
  this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
1503
1512
  this.observing_ = [];
1504
1513
  this.newObserving_ = null;
1505
- this.isBeingObserved_ = false;
1506
- this.isPendingUnobservation_ = false;
1507
1514
  this.observers_ = new Set();
1508
1515
  this.diffValue_ = 0;
1509
1516
  this.runId_ = 0;
@@ -1513,8 +1520,7 @@ var ComputedValue = /*#__PURE__*/function () {
1513
1520
  this.value_ = new CaughtException(null);
1514
1521
  this.name_ = void 0;
1515
1522
  this.triggeredBy_ = void 0;
1516
- this.isComputing_ = false;
1517
- this.isRunningSetter_ = false;
1523
+ this.flags_ = 0;
1518
1524
  this.derivation = void 0;
1519
1525
  this.setter_ = void 0;
1520
1526
  this.isTracing_ = TraceMode.NONE;
@@ -1555,12 +1561,14 @@ var ComputedValue = /*#__PURE__*/function () {
1555
1561
  });
1556
1562
  }
1557
1563
  }
1564
+ // to check for cycles
1565
+ ;
1558
1566
  /**
1559
1567
  * Returns the current value of this computed value.
1560
1568
  * Will evaluate its computation first if needed.
1561
- */;
1569
+ */
1562
1570
  _proto.get = function get() {
1563
- if (this.isComputing_) {
1571
+ if (this.isComputing) {
1564
1572
  die(32, this.name_, this.derivation);
1565
1573
  }
1566
1574
  if (globalState.inBatch === 0 &&
@@ -1593,14 +1601,14 @@ var ComputedValue = /*#__PURE__*/function () {
1593
1601
  };
1594
1602
  _proto.set = function set(value) {
1595
1603
  if (this.setter_) {
1596
- if (this.isRunningSetter_) {
1604
+ if (this.isRunningSetter) {
1597
1605
  die(33, this.name_);
1598
1606
  }
1599
- this.isRunningSetter_ = true;
1607
+ this.isRunningSetter = true;
1600
1608
  try {
1601
1609
  this.setter_.call(this.scope_, value);
1602
1610
  } finally {
1603
- this.isRunningSetter_ = false;
1611
+ this.isRunningSetter = false;
1604
1612
  }
1605
1613
  } else {
1606
1614
  die(34, this.name_);
@@ -1628,7 +1636,7 @@ var ComputedValue = /*#__PURE__*/function () {
1628
1636
  return changed;
1629
1637
  };
1630
1638
  _proto.computeValue_ = function computeValue_(track) {
1631
- this.isComputing_ = true;
1639
+ this.isComputing = true;
1632
1640
  // don't allow state changes during computation
1633
1641
  var prev = allowStateChangesStart(false);
1634
1642
  var res;
@@ -1646,7 +1654,7 @@ var ComputedValue = /*#__PURE__*/function () {
1646
1654
  }
1647
1655
  }
1648
1656
  allowStateChangesEnd(prev);
1649
- this.isComputing_ = false;
1657
+ this.isComputing = false;
1650
1658
  return res;
1651
1659
  };
1652
1660
  _proto.suspend_ = function suspend_() {
@@ -1701,8 +1709,45 @@ var ComputedValue = /*#__PURE__*/function () {
1701
1709
  _proto[_Symbol$toPrimitive$1] = function () {
1702
1710
  return this.valueOf();
1703
1711
  };
1712
+ _createClass(ComputedValue, [{
1713
+ key: "isComputing",
1714
+ get: function get() {
1715
+ return getFlag(this.flags_, ComputedValue.isComputingMask_);
1716
+ },
1717
+ set: function set(newValue) {
1718
+ this.flags_ = setFlag(this.flags_, ComputedValue.isComputingMask_, newValue);
1719
+ }
1720
+ }, {
1721
+ key: "isRunningSetter",
1722
+ get: function get() {
1723
+ return getFlag(this.flags_, ComputedValue.isRunningSetterMask_);
1724
+ },
1725
+ set: function set(newValue) {
1726
+ this.flags_ = setFlag(this.flags_, ComputedValue.isRunningSetterMask_, newValue);
1727
+ }
1728
+ }, {
1729
+ key: "isBeingObserved",
1730
+ get: function get() {
1731
+ return getFlag(this.flags_, ComputedValue.isBeingObservedMask_);
1732
+ },
1733
+ set: function set(newValue) {
1734
+ this.flags_ = setFlag(this.flags_, ComputedValue.isBeingObservedMask_, newValue);
1735
+ }
1736
+ }, {
1737
+ key: "isPendingUnobservation",
1738
+ get: function get() {
1739
+ return getFlag(this.flags_, ComputedValue.isPendingUnobservationMask_);
1740
+ },
1741
+ set: function set(newValue) {
1742
+ this.flags_ = setFlag(this.flags_, ComputedValue.isPendingUnobservationMask_, newValue);
1743
+ }
1744
+ }]);
1704
1745
  return ComputedValue;
1705
1746
  }();
1747
+ ComputedValue.isComputingMask_ = 1;
1748
+ ComputedValue.isRunningSetterMask_ = 2;
1749
+ ComputedValue.isBeingObservedMask_ = 4;
1750
+ ComputedValue.isPendingUnobservationMask_ = 8;
1706
1751
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1707
1752
 
1708
1753
  var IDerivationState_;
@@ -2110,9 +2155,9 @@ function removeObserver(observable, node) {
2110
2155
  }
2111
2156
 
2112
2157
  function queueForUnobservation(observable) {
2113
- if (observable.isPendingUnobservation_ === false) {
2158
+ if (observable.isPendingUnobservation === false) {
2114
2159
  // invariant(observable._observers.length === 0, "INTERNAL ERROR, should only queue for unobservation unobserved observables");
2115
- observable.isPendingUnobservation_ = true;
2160
+ observable.isPendingUnobservation = true;
2116
2161
  globalState.pendingUnobservations.push(observable);
2117
2162
  }
2118
2163
  }
@@ -2131,11 +2176,11 @@ function endBatch() {
2131
2176
  var list = globalState.pendingUnobservations;
2132
2177
  for (var i = 0; i < list.length; i++) {
2133
2178
  var observable = list[i];
2134
- observable.isPendingUnobservation_ = false;
2179
+ observable.isPendingUnobservation = false;
2135
2180
  if (observable.observers_.size === 0) {
2136
- if (observable.isBeingObserved_) {
2181
+ if (observable.isBeingObserved) {
2137
2182
  // if this observable had reactive observers, trigger the hooks
2138
- observable.isBeingObserved_ = false;
2183
+ observable.isBeingObserved = false;
2139
2184
  observable.onBUO();
2140
2185
  }
2141
2186
  if (observable instanceof ComputedValue) {
@@ -2161,12 +2206,12 @@ function reportObserved(observable) {
2161
2206
  observable.lastAccessedBy_ = derivation.runId_;
2162
2207
  // Tried storing newObserving, or observing, or both as Set, but performance didn't come close...
2163
2208
  derivation.newObserving_[derivation.unboundDepsCount_++] = observable;
2164
- if (!observable.isBeingObserved_ && globalState.trackingContext) {
2165
- observable.isBeingObserved_ = true;
2209
+ if (!observable.isBeingObserved && globalState.trackingContext) {
2210
+ observable.isBeingObserved = true;
2166
2211
  observable.onBO();
2167
2212
  }
2168
2213
  }
2169
- return observable.isBeingObserved_;
2214
+ return observable.isBeingObserved;
2170
2215
  } else if (observable.observers_.size === 0 && globalState.inBatch > 0) {
2171
2216
  queueForUnobservation(observable);
2172
2217
  }