mobx 6.12.1 → 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.
@@ -433,8 +433,8 @@ var Atom = /*#__PURE__*/function () {
433
433
  name_ = "Atom@" + getNextId() ;
434
434
  }
435
435
  this.name_ = void 0;
436
- this.isPendingUnobservation_ = false;
437
- this.isBeingObserved_ = false;
436
+ this.isPendingUnobservation = false;
437
+ this.isBeingObserved = false;
438
438
  this.observers_ = new Set();
439
439
  this.diffValue_ = 0;
440
440
  this.lastAccessedBy_ = 0;
@@ -1457,6 +1457,17 @@ var ObservableValue = /*#__PURE__*/function (_Atom) {
1457
1457
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1458
1458
 
1459
1459
  var _Symbol$toPrimitive$1;
1460
+ function getFlag(flags, mask) {
1461
+ return !!(flags & mask);
1462
+ }
1463
+ function setFlag(flags, mask, newValue) {
1464
+ if (newValue) {
1465
+ flags |= mask;
1466
+ } else {
1467
+ flags &= ~mask;
1468
+ }
1469
+ return flags;
1470
+ }
1460
1471
  /**
1461
1472
  * A node in the state dependency root that observes other nodes, and can be observed itself.
1462
1473
  *
@@ -1481,8 +1492,6 @@ var ComputedValue = /*#__PURE__*/function () {
1481
1492
  // nodes we are looking at. Our value depends on these nodes
1482
1493
  // during tracking it's an array with new observed observers
1483
1494
 
1484
- // to check for cycles
1485
-
1486
1495
  // N.B: unminified as it is used by MST
1487
1496
 
1488
1497
  /**
@@ -1501,8 +1510,6 @@ var ComputedValue = /*#__PURE__*/function () {
1501
1510
  this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
1502
1511
  this.observing_ = [];
1503
1512
  this.newObserving_ = null;
1504
- this.isBeingObserved_ = false;
1505
- this.isPendingUnobservation_ = false;
1506
1513
  this.observers_ = new Set();
1507
1514
  this.diffValue_ = 0;
1508
1515
  this.runId_ = 0;
@@ -1512,8 +1519,7 @@ var ComputedValue = /*#__PURE__*/function () {
1512
1519
  this.value_ = new CaughtException(null);
1513
1520
  this.name_ = void 0;
1514
1521
  this.triggeredBy_ = void 0;
1515
- this.isComputing_ = false;
1516
- this.isRunningSetter_ = false;
1522
+ this.flags_ = 0;
1517
1523
  this.derivation = void 0;
1518
1524
  this.setter_ = void 0;
1519
1525
  this.isTracing_ = TraceMode.NONE;
@@ -1554,12 +1560,14 @@ var ComputedValue = /*#__PURE__*/function () {
1554
1560
  });
1555
1561
  }
1556
1562
  }
1563
+ // to check for cycles
1564
+ ;
1557
1565
  /**
1558
1566
  * Returns the current value of this computed value.
1559
1567
  * Will evaluate its computation first if needed.
1560
- */;
1568
+ */
1561
1569
  _proto.get = function get() {
1562
- if (this.isComputing_) {
1570
+ if (this.isComputing) {
1563
1571
  die(32, this.name_, this.derivation);
1564
1572
  }
1565
1573
  if (globalState.inBatch === 0 &&
@@ -1592,14 +1600,14 @@ var ComputedValue = /*#__PURE__*/function () {
1592
1600
  };
1593
1601
  _proto.set = function set(value) {
1594
1602
  if (this.setter_) {
1595
- if (this.isRunningSetter_) {
1603
+ if (this.isRunningSetter) {
1596
1604
  die(33, this.name_);
1597
1605
  }
1598
- this.isRunningSetter_ = true;
1606
+ this.isRunningSetter = true;
1599
1607
  try {
1600
1608
  this.setter_.call(this.scope_, value);
1601
1609
  } finally {
1602
- this.isRunningSetter_ = false;
1610
+ this.isRunningSetter = false;
1603
1611
  }
1604
1612
  } else {
1605
1613
  die(34, this.name_);
@@ -1627,7 +1635,7 @@ var ComputedValue = /*#__PURE__*/function () {
1627
1635
  return changed;
1628
1636
  };
1629
1637
  _proto.computeValue_ = function computeValue_(track) {
1630
- this.isComputing_ = true;
1638
+ this.isComputing = true;
1631
1639
  // don't allow state changes during computation
1632
1640
  var prev = allowStateChangesStart(false);
1633
1641
  var res;
@@ -1645,7 +1653,7 @@ var ComputedValue = /*#__PURE__*/function () {
1645
1653
  }
1646
1654
  }
1647
1655
  allowStateChangesEnd(prev);
1648
- this.isComputing_ = false;
1656
+ this.isComputing = false;
1649
1657
  return res;
1650
1658
  };
1651
1659
  _proto.suspend_ = function suspend_() {
@@ -1697,8 +1705,45 @@ var ComputedValue = /*#__PURE__*/function () {
1697
1705
  _proto[_Symbol$toPrimitive$1] = function () {
1698
1706
  return this.valueOf();
1699
1707
  };
1708
+ _createClass(ComputedValue, [{
1709
+ key: "isComputing",
1710
+ get: function get() {
1711
+ return getFlag(this.flags_, ComputedValue.isComputingMask_);
1712
+ },
1713
+ set: function set(newValue) {
1714
+ this.flags_ = setFlag(this.flags_, ComputedValue.isComputingMask_, newValue);
1715
+ }
1716
+ }, {
1717
+ key: "isRunningSetter",
1718
+ get: function get() {
1719
+ return getFlag(this.flags_, ComputedValue.isRunningSetterMask_);
1720
+ },
1721
+ set: function set(newValue) {
1722
+ this.flags_ = setFlag(this.flags_, ComputedValue.isRunningSetterMask_, newValue);
1723
+ }
1724
+ }, {
1725
+ key: "isBeingObserved",
1726
+ get: function get() {
1727
+ return getFlag(this.flags_, ComputedValue.isBeingObservedMask_);
1728
+ },
1729
+ set: function set(newValue) {
1730
+ this.flags_ = setFlag(this.flags_, ComputedValue.isBeingObservedMask_, newValue);
1731
+ }
1732
+ }, {
1733
+ key: "isPendingUnobservation",
1734
+ get: function get() {
1735
+ return getFlag(this.flags_, ComputedValue.isPendingUnobservationMask_);
1736
+ },
1737
+ set: function set(newValue) {
1738
+ this.flags_ = setFlag(this.flags_, ComputedValue.isPendingUnobservationMask_, newValue);
1739
+ }
1740
+ }]);
1700
1741
  return ComputedValue;
1701
1742
  }();
1743
+ ComputedValue.isComputingMask_ = 1;
1744
+ ComputedValue.isRunningSetterMask_ = 2;
1745
+ ComputedValue.isBeingObservedMask_ = 4;
1746
+ ComputedValue.isPendingUnobservationMask_ = 8;
1702
1747
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1703
1748
 
1704
1749
  var IDerivationState_;
@@ -2100,9 +2145,9 @@ function removeObserver(observable, node) {
2100
2145
  }
2101
2146
 
2102
2147
  function queueForUnobservation(observable) {
2103
- if (observable.isPendingUnobservation_ === false) {
2148
+ if (observable.isPendingUnobservation === false) {
2104
2149
  // invariant(observable._observers.length === 0, "INTERNAL ERROR, should only queue for unobservation unobserved observables");
2105
- observable.isPendingUnobservation_ = true;
2150
+ observable.isPendingUnobservation = true;
2106
2151
  globalState.pendingUnobservations.push(observable);
2107
2152
  }
2108
2153
  }
@@ -2121,11 +2166,11 @@ function endBatch() {
2121
2166
  var list = globalState.pendingUnobservations;
2122
2167
  for (var i = 0; i < list.length; i++) {
2123
2168
  var observable = list[i];
2124
- observable.isPendingUnobservation_ = false;
2169
+ observable.isPendingUnobservation = false;
2125
2170
  if (observable.observers_.size === 0) {
2126
- if (observable.isBeingObserved_) {
2171
+ if (observable.isBeingObserved) {
2127
2172
  // if this observable had reactive observers, trigger the hooks
2128
- observable.isBeingObserved_ = false;
2173
+ observable.isBeingObserved = false;
2129
2174
  observable.onBUO();
2130
2175
  }
2131
2176
  if (observable instanceof ComputedValue) {
@@ -2151,12 +2196,12 @@ function reportObserved(observable) {
2151
2196
  observable.lastAccessedBy_ = derivation.runId_;
2152
2197
  // Tried storing newObserving, or observing, or both as Set, but performance didn't come close...
2153
2198
  derivation.newObserving_[derivation.unboundDepsCount_++] = observable;
2154
- if (!observable.isBeingObserved_ && globalState.trackingContext) {
2155
- observable.isBeingObserved_ = true;
2199
+ if (!observable.isBeingObserved && globalState.trackingContext) {
2200
+ observable.isBeingObserved = true;
2156
2201
  observable.onBO();
2157
2202
  }
2158
2203
  }
2159
- return observable.isBeingObserved_;
2204
+ return observable.isBeingObserved;
2160
2205
  } else if (observable.observers_.size === 0 && globalState.inBatch > 0) {
2161
2206
  queueForUnobservation(observable);
2162
2207
  }