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.
@@ -439,8 +439,8 @@
439
439
  name_ = "Atom@" + getNextId() ;
440
440
  }
441
441
  this.name_ = void 0;
442
- this.isPendingUnobservation_ = false;
443
- this.isBeingObserved_ = false;
442
+ this.isPendingUnobservation = false;
443
+ this.isBeingObserved = false;
444
444
  this.observers_ = new Set();
445
445
  this.diffValue_ = 0;
446
446
  this.lastAccessedBy_ = 0;
@@ -1463,6 +1463,17 @@
1463
1463
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1464
1464
 
1465
1465
  var _Symbol$toPrimitive$1;
1466
+ function getFlag(flags, mask) {
1467
+ return !!(flags & mask);
1468
+ }
1469
+ function setFlag(flags, mask, newValue) {
1470
+ if (newValue) {
1471
+ flags |= mask;
1472
+ } else {
1473
+ flags &= ~mask;
1474
+ }
1475
+ return flags;
1476
+ }
1466
1477
  /**
1467
1478
  * A node in the state dependency root that observes other nodes, and can be observed itself.
1468
1479
  *
@@ -1487,8 +1498,6 @@
1487
1498
  // nodes we are looking at. Our value depends on these nodes
1488
1499
  // during tracking it's an array with new observed observers
1489
1500
 
1490
- // to check for cycles
1491
-
1492
1501
  // N.B: unminified as it is used by MST
1493
1502
 
1494
1503
  /**
@@ -1507,8 +1516,6 @@
1507
1516
  this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
1508
1517
  this.observing_ = [];
1509
1518
  this.newObserving_ = null;
1510
- this.isBeingObserved_ = false;
1511
- this.isPendingUnobservation_ = false;
1512
1519
  this.observers_ = new Set();
1513
1520
  this.diffValue_ = 0;
1514
1521
  this.runId_ = 0;
@@ -1518,8 +1525,7 @@
1518
1525
  this.value_ = new CaughtException(null);
1519
1526
  this.name_ = void 0;
1520
1527
  this.triggeredBy_ = void 0;
1521
- this.isComputing_ = false;
1522
- this.isRunningSetter_ = false;
1528
+ this.flags_ = 0;
1523
1529
  this.derivation = void 0;
1524
1530
  this.setter_ = void 0;
1525
1531
  this.isTracing_ = TraceMode.NONE;
@@ -1560,12 +1566,14 @@
1560
1566
  });
1561
1567
  }
1562
1568
  }
1569
+ // to check for cycles
1570
+ ;
1563
1571
  /**
1564
1572
  * Returns the current value of this computed value.
1565
1573
  * Will evaluate its computation first if needed.
1566
- */;
1574
+ */
1567
1575
  _proto.get = function get() {
1568
- if (this.isComputing_) {
1576
+ if (this.isComputing) {
1569
1577
  die(32, this.name_, this.derivation);
1570
1578
  }
1571
1579
  if (globalState.inBatch === 0 &&
@@ -1598,14 +1606,14 @@
1598
1606
  };
1599
1607
  _proto.set = function set(value) {
1600
1608
  if (this.setter_) {
1601
- if (this.isRunningSetter_) {
1609
+ if (this.isRunningSetter) {
1602
1610
  die(33, this.name_);
1603
1611
  }
1604
- this.isRunningSetter_ = true;
1612
+ this.isRunningSetter = true;
1605
1613
  try {
1606
1614
  this.setter_.call(this.scope_, value);
1607
1615
  } finally {
1608
- this.isRunningSetter_ = false;
1616
+ this.isRunningSetter = false;
1609
1617
  }
1610
1618
  } else {
1611
1619
  die(34, this.name_);
@@ -1633,7 +1641,7 @@
1633
1641
  return changed;
1634
1642
  };
1635
1643
  _proto.computeValue_ = function computeValue_(track) {
1636
- this.isComputing_ = true;
1644
+ this.isComputing = true;
1637
1645
  // don't allow state changes during computation
1638
1646
  var prev = allowStateChangesStart(false);
1639
1647
  var res;
@@ -1651,7 +1659,7 @@
1651
1659
  }
1652
1660
  }
1653
1661
  allowStateChangesEnd(prev);
1654
- this.isComputing_ = false;
1662
+ this.isComputing = false;
1655
1663
  return res;
1656
1664
  };
1657
1665
  _proto.suspend_ = function suspend_() {
@@ -1703,8 +1711,45 @@
1703
1711
  _proto[_Symbol$toPrimitive$1] = function () {
1704
1712
  return this.valueOf();
1705
1713
  };
1714
+ _createClass(ComputedValue, [{
1715
+ key: "isComputing",
1716
+ get: function get() {
1717
+ return getFlag(this.flags_, ComputedValue.isComputingMask_);
1718
+ },
1719
+ set: function set(newValue) {
1720
+ this.flags_ = setFlag(this.flags_, ComputedValue.isComputingMask_, newValue);
1721
+ }
1722
+ }, {
1723
+ key: "isRunningSetter",
1724
+ get: function get() {
1725
+ return getFlag(this.flags_, ComputedValue.isRunningSetterMask_);
1726
+ },
1727
+ set: function set(newValue) {
1728
+ this.flags_ = setFlag(this.flags_, ComputedValue.isRunningSetterMask_, newValue);
1729
+ }
1730
+ }, {
1731
+ key: "isBeingObserved",
1732
+ get: function get() {
1733
+ return getFlag(this.flags_, ComputedValue.isBeingObservedMask_);
1734
+ },
1735
+ set: function set(newValue) {
1736
+ this.flags_ = setFlag(this.flags_, ComputedValue.isBeingObservedMask_, newValue);
1737
+ }
1738
+ }, {
1739
+ key: "isPendingUnobservation",
1740
+ get: function get() {
1741
+ return getFlag(this.flags_, ComputedValue.isPendingUnobservationMask_);
1742
+ },
1743
+ set: function set(newValue) {
1744
+ this.flags_ = setFlag(this.flags_, ComputedValue.isPendingUnobservationMask_, newValue);
1745
+ }
1746
+ }]);
1706
1747
  return ComputedValue;
1707
1748
  }();
1749
+ ComputedValue.isComputingMask_ = 1;
1750
+ ComputedValue.isRunningSetterMask_ = 2;
1751
+ ComputedValue.isBeingObservedMask_ = 4;
1752
+ ComputedValue.isPendingUnobservationMask_ = 8;
1708
1753
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1709
1754
 
1710
1755
  var IDerivationState_;
@@ -2106,9 +2151,9 @@
2106
2151
  }
2107
2152
 
2108
2153
  function queueForUnobservation(observable) {
2109
- if (observable.isPendingUnobservation_ === false) {
2154
+ if (observable.isPendingUnobservation === false) {
2110
2155
  // invariant(observable._observers.length === 0, "INTERNAL ERROR, should only queue for unobservation unobserved observables");
2111
- observable.isPendingUnobservation_ = true;
2156
+ observable.isPendingUnobservation = true;
2112
2157
  globalState.pendingUnobservations.push(observable);
2113
2158
  }
2114
2159
  }
@@ -2127,11 +2172,11 @@
2127
2172
  var list = globalState.pendingUnobservations;
2128
2173
  for (var i = 0; i < list.length; i++) {
2129
2174
  var observable = list[i];
2130
- observable.isPendingUnobservation_ = false;
2175
+ observable.isPendingUnobservation = false;
2131
2176
  if (observable.observers_.size === 0) {
2132
- if (observable.isBeingObserved_) {
2177
+ if (observable.isBeingObserved) {
2133
2178
  // if this observable had reactive observers, trigger the hooks
2134
- observable.isBeingObserved_ = false;
2179
+ observable.isBeingObserved = false;
2135
2180
  observable.onBUO();
2136
2181
  }
2137
2182
  if (observable instanceof ComputedValue) {
@@ -2157,12 +2202,12 @@
2157
2202
  observable.lastAccessedBy_ = derivation.runId_;
2158
2203
  // Tried storing newObserving, or observing, or both as Set, but performance didn't come close...
2159
2204
  derivation.newObserving_[derivation.unboundDepsCount_++] = observable;
2160
- if (!observable.isBeingObserved_ && globalState.trackingContext) {
2161
- observable.isBeingObserved_ = true;
2205
+ if (!observable.isBeingObserved && globalState.trackingContext) {
2206
+ observable.isBeingObserved = true;
2162
2207
  observable.onBO();
2163
2208
  }
2164
2209
  }
2165
- return observable.isBeingObserved_;
2210
+ return observable.isBeingObserved;
2166
2211
  } else if (observable.observers_.size === 0 && globalState.inBatch > 0) {
2167
2212
  queueForUnobservation(observable);
2168
2213
  }