mobx 6.12.3 → 6.12.5

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.
@@ -203,10 +203,16 @@ function createInstanceofPredicate(name, theClass) {
203
203
  };
204
204
  }
205
205
  function isES6Map(thing) {
206
- return thing instanceof Map;
206
+ return thing != null && Object.prototype.toString.call(thing) === "[object Map]";
207
+ }
208
+ function isPlainES6Map(thing) {
209
+ var mapProto = Object.getPrototypeOf(thing);
210
+ var objectProto = Object.getPrototypeOf(mapProto);
211
+ var nullProto = Object.getPrototypeOf(objectProto);
212
+ return nullProto === null;
207
213
  }
208
214
  function isES6Set(thing) {
209
- return thing instanceof Set;
215
+ return thing != null && Object.prototype.toString.call(thing) === "[object Set]";
210
216
  }
211
217
  var hasGetOwnPropertySymbols = typeof Object.getOwnPropertySymbols !== "undefined";
212
218
  /**
@@ -433,8 +439,8 @@ var Atom = /*#__PURE__*/function () {
433
439
  name_ = "Atom@" + getNextId() ;
434
440
  }
435
441
  this.name_ = void 0;
436
- this.isPendingUnobservation_ = false;
437
- this.isBeingObserved_ = false;
442
+ this.isPendingUnobservation = false;
443
+ this.isBeingObserved = false;
438
444
  this.observers_ = new Set();
439
445
  this.diffValue_ = 0;
440
446
  this.lastAccessedBy_ = 0;
@@ -1457,6 +1463,17 @@ var ObservableValue = /*#__PURE__*/function (_Atom) {
1457
1463
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1458
1464
 
1459
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
+ }
1460
1477
  /**
1461
1478
  * A node in the state dependency root that observes other nodes, and can be observed itself.
1462
1479
  *
@@ -1481,8 +1498,6 @@ var ComputedValue = /*#__PURE__*/function () {
1481
1498
  // nodes we are looking at. Our value depends on these nodes
1482
1499
  // during tracking it's an array with new observed observers
1483
1500
 
1484
- // to check for cycles
1485
-
1486
1501
  // N.B: unminified as it is used by MST
1487
1502
 
1488
1503
  /**
@@ -1501,8 +1516,6 @@ var ComputedValue = /*#__PURE__*/function () {
1501
1516
  this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
1502
1517
  this.observing_ = [];
1503
1518
  this.newObserving_ = null;
1504
- this.isBeingObserved_ = false;
1505
- this.isPendingUnobservation_ = false;
1506
1519
  this.observers_ = new Set();
1507
1520
  this.diffValue_ = 0;
1508
1521
  this.runId_ = 0;
@@ -1512,8 +1525,7 @@ var ComputedValue = /*#__PURE__*/function () {
1512
1525
  this.value_ = new CaughtException(null);
1513
1526
  this.name_ = void 0;
1514
1527
  this.triggeredBy_ = void 0;
1515
- this.isComputing_ = false;
1516
- this.isRunningSetter_ = false;
1528
+ this.flags_ = 0;
1517
1529
  this.derivation = void 0;
1518
1530
  this.setter_ = void 0;
1519
1531
  this.isTracing_ = TraceMode.NONE;
@@ -1554,12 +1566,14 @@ var ComputedValue = /*#__PURE__*/function () {
1554
1566
  });
1555
1567
  }
1556
1568
  }
1569
+ // to check for cycles
1570
+ ;
1557
1571
  /**
1558
1572
  * Returns the current value of this computed value.
1559
1573
  * Will evaluate its computation first if needed.
1560
- */;
1574
+ */
1561
1575
  _proto.get = function get() {
1562
- if (this.isComputing_) {
1576
+ if (this.isComputing) {
1563
1577
  die(32, this.name_, this.derivation);
1564
1578
  }
1565
1579
  if (globalState.inBatch === 0 &&
@@ -1592,14 +1606,14 @@ var ComputedValue = /*#__PURE__*/function () {
1592
1606
  };
1593
1607
  _proto.set = function set(value) {
1594
1608
  if (this.setter_) {
1595
- if (this.isRunningSetter_) {
1609
+ if (this.isRunningSetter) {
1596
1610
  die(33, this.name_);
1597
1611
  }
1598
- this.isRunningSetter_ = true;
1612
+ this.isRunningSetter = true;
1599
1613
  try {
1600
1614
  this.setter_.call(this.scope_, value);
1601
1615
  } finally {
1602
- this.isRunningSetter_ = false;
1616
+ this.isRunningSetter = false;
1603
1617
  }
1604
1618
  } else {
1605
1619
  die(34, this.name_);
@@ -1627,7 +1641,7 @@ var ComputedValue = /*#__PURE__*/function () {
1627
1641
  return changed;
1628
1642
  };
1629
1643
  _proto.computeValue_ = function computeValue_(track) {
1630
- this.isComputing_ = true;
1644
+ this.isComputing = true;
1631
1645
  // don't allow state changes during computation
1632
1646
  var prev = allowStateChangesStart(false);
1633
1647
  var res;
@@ -1645,7 +1659,7 @@ var ComputedValue = /*#__PURE__*/function () {
1645
1659
  }
1646
1660
  }
1647
1661
  allowStateChangesEnd(prev);
1648
- this.isComputing_ = false;
1662
+ this.isComputing = false;
1649
1663
  return res;
1650
1664
  };
1651
1665
  _proto.suspend_ = function suspend_() {
@@ -1697,8 +1711,45 @@ var ComputedValue = /*#__PURE__*/function () {
1697
1711
  _proto[_Symbol$toPrimitive$1] = function () {
1698
1712
  return this.valueOf();
1699
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
+ }]);
1700
1747
  return ComputedValue;
1701
1748
  }();
1749
+ ComputedValue.isComputingMask_ = 1;
1750
+ ComputedValue.isRunningSetterMask_ = 2;
1751
+ ComputedValue.isBeingObservedMask_ = 4;
1752
+ ComputedValue.isPendingUnobservationMask_ = 8;
1702
1753
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1703
1754
 
1704
1755
  var IDerivationState_;
@@ -2100,9 +2151,9 @@ function removeObserver(observable, node) {
2100
2151
  }
2101
2152
 
2102
2153
  function queueForUnobservation(observable) {
2103
- if (observable.isPendingUnobservation_ === false) {
2154
+ if (observable.isPendingUnobservation === false) {
2104
2155
  // invariant(observable._observers.length === 0, "INTERNAL ERROR, should only queue for unobservation unobserved observables");
2105
- observable.isPendingUnobservation_ = true;
2156
+ observable.isPendingUnobservation = true;
2106
2157
  globalState.pendingUnobservations.push(observable);
2107
2158
  }
2108
2159
  }
@@ -2121,11 +2172,11 @@ function endBatch() {
2121
2172
  var list = globalState.pendingUnobservations;
2122
2173
  for (var i = 0; i < list.length; i++) {
2123
2174
  var observable = list[i];
2124
- observable.isPendingUnobservation_ = false;
2175
+ observable.isPendingUnobservation = false;
2125
2176
  if (observable.observers_.size === 0) {
2126
- if (observable.isBeingObserved_) {
2177
+ if (observable.isBeingObserved) {
2127
2178
  // if this observable had reactive observers, trigger the hooks
2128
- observable.isBeingObserved_ = false;
2179
+ observable.isBeingObserved = false;
2129
2180
  observable.onBUO();
2130
2181
  }
2131
2182
  if (observable instanceof ComputedValue) {
@@ -2151,12 +2202,12 @@ function reportObserved(observable) {
2151
2202
  observable.lastAccessedBy_ = derivation.runId_;
2152
2203
  // Tried storing newObserving, or observing, or both as Set, but performance didn't come close...
2153
2204
  derivation.newObserving_[derivation.unboundDepsCount_++] = observable;
2154
- if (!observable.isBeingObserved_ && globalState.trackingContext) {
2155
- observable.isBeingObserved_ = true;
2205
+ if (!observable.isBeingObserved && globalState.trackingContext) {
2206
+ observable.isBeingObserved = true;
2156
2207
  observable.onBO();
2157
2208
  }
2158
2209
  }
2159
- return observable.isBeingObserved_;
2210
+ return observable.isBeingObserved;
2160
2211
  } else if (observable.observers_.size === 0 && globalState.inBatch > 0) {
2161
2212
  queueForUnobservation(observable);
2162
2213
  }
@@ -4281,7 +4332,7 @@ var ObservableMap = /*#__PURE__*/function () {
4281
4332
  return _this5.set(key, value);
4282
4333
  });
4283
4334
  } else if (isES6Map(other)) {
4284
- if (other.constructor !== Map) {
4335
+ if (!isPlainES6Map(other)) {
4285
4336
  die(19, other);
4286
4337
  }
4287
4338
  other.forEach(function (value, key) {