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.
@@ -209,10 +209,16 @@
209
209
  };
210
210
  }
211
211
  function isES6Map(thing) {
212
- return thing instanceof Map;
212
+ return thing != null && Object.prototype.toString.call(thing) === "[object Map]";
213
+ }
214
+ function isPlainES6Map(thing) {
215
+ var mapProto = Object.getPrototypeOf(thing);
216
+ var objectProto = Object.getPrototypeOf(mapProto);
217
+ var nullProto = Object.getPrototypeOf(objectProto);
218
+ return nullProto === null;
213
219
  }
214
220
  function isES6Set(thing) {
215
- return thing instanceof Set;
221
+ return thing != null && Object.prototype.toString.call(thing) === "[object Set]";
216
222
  }
217
223
  var hasGetOwnPropertySymbols = typeof Object.getOwnPropertySymbols !== "undefined";
218
224
  /**
@@ -439,8 +445,8 @@
439
445
  name_ = "Atom@" + getNextId() ;
440
446
  }
441
447
  this.name_ = void 0;
442
- this.isPendingUnobservation_ = false;
443
- this.isBeingObserved_ = false;
448
+ this.isPendingUnobservation = false;
449
+ this.isBeingObserved = false;
444
450
  this.observers_ = new Set();
445
451
  this.diffValue_ = 0;
446
452
  this.lastAccessedBy_ = 0;
@@ -1463,6 +1469,17 @@
1463
1469
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1464
1470
 
1465
1471
  var _Symbol$toPrimitive$1;
1472
+ function getFlag(flags, mask) {
1473
+ return !!(flags & mask);
1474
+ }
1475
+ function setFlag(flags, mask, newValue) {
1476
+ if (newValue) {
1477
+ flags |= mask;
1478
+ } else {
1479
+ flags &= ~mask;
1480
+ }
1481
+ return flags;
1482
+ }
1466
1483
  /**
1467
1484
  * A node in the state dependency root that observes other nodes, and can be observed itself.
1468
1485
  *
@@ -1487,8 +1504,6 @@
1487
1504
  // nodes we are looking at. Our value depends on these nodes
1488
1505
  // during tracking it's an array with new observed observers
1489
1506
 
1490
- // to check for cycles
1491
-
1492
1507
  // N.B: unminified as it is used by MST
1493
1508
 
1494
1509
  /**
@@ -1507,8 +1522,6 @@
1507
1522
  this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
1508
1523
  this.observing_ = [];
1509
1524
  this.newObserving_ = null;
1510
- this.isBeingObserved_ = false;
1511
- this.isPendingUnobservation_ = false;
1512
1525
  this.observers_ = new Set();
1513
1526
  this.diffValue_ = 0;
1514
1527
  this.runId_ = 0;
@@ -1518,8 +1531,7 @@
1518
1531
  this.value_ = new CaughtException(null);
1519
1532
  this.name_ = void 0;
1520
1533
  this.triggeredBy_ = void 0;
1521
- this.isComputing_ = false;
1522
- this.isRunningSetter_ = false;
1534
+ this.flags_ = 0;
1523
1535
  this.derivation = void 0;
1524
1536
  this.setter_ = void 0;
1525
1537
  this.isTracing_ = TraceMode.NONE;
@@ -1560,12 +1572,14 @@
1560
1572
  });
1561
1573
  }
1562
1574
  }
1575
+ // to check for cycles
1576
+ ;
1563
1577
  /**
1564
1578
  * Returns the current value of this computed value.
1565
1579
  * Will evaluate its computation first if needed.
1566
- */;
1580
+ */
1567
1581
  _proto.get = function get() {
1568
- if (this.isComputing_) {
1582
+ if (this.isComputing) {
1569
1583
  die(32, this.name_, this.derivation);
1570
1584
  }
1571
1585
  if (globalState.inBatch === 0 &&
@@ -1598,14 +1612,14 @@
1598
1612
  };
1599
1613
  _proto.set = function set(value) {
1600
1614
  if (this.setter_) {
1601
- if (this.isRunningSetter_) {
1615
+ if (this.isRunningSetter) {
1602
1616
  die(33, this.name_);
1603
1617
  }
1604
- this.isRunningSetter_ = true;
1618
+ this.isRunningSetter = true;
1605
1619
  try {
1606
1620
  this.setter_.call(this.scope_, value);
1607
1621
  } finally {
1608
- this.isRunningSetter_ = false;
1622
+ this.isRunningSetter = false;
1609
1623
  }
1610
1624
  } else {
1611
1625
  die(34, this.name_);
@@ -1633,7 +1647,7 @@
1633
1647
  return changed;
1634
1648
  };
1635
1649
  _proto.computeValue_ = function computeValue_(track) {
1636
- this.isComputing_ = true;
1650
+ this.isComputing = true;
1637
1651
  // don't allow state changes during computation
1638
1652
  var prev = allowStateChangesStart(false);
1639
1653
  var res;
@@ -1651,7 +1665,7 @@
1651
1665
  }
1652
1666
  }
1653
1667
  allowStateChangesEnd(prev);
1654
- this.isComputing_ = false;
1668
+ this.isComputing = false;
1655
1669
  return res;
1656
1670
  };
1657
1671
  _proto.suspend_ = function suspend_() {
@@ -1703,8 +1717,45 @@
1703
1717
  _proto[_Symbol$toPrimitive$1] = function () {
1704
1718
  return this.valueOf();
1705
1719
  };
1720
+ _createClass(ComputedValue, [{
1721
+ key: "isComputing",
1722
+ get: function get() {
1723
+ return getFlag(this.flags_, ComputedValue.isComputingMask_);
1724
+ },
1725
+ set: function set(newValue) {
1726
+ this.flags_ = setFlag(this.flags_, ComputedValue.isComputingMask_, newValue);
1727
+ }
1728
+ }, {
1729
+ key: "isRunningSetter",
1730
+ get: function get() {
1731
+ return getFlag(this.flags_, ComputedValue.isRunningSetterMask_);
1732
+ },
1733
+ set: function set(newValue) {
1734
+ this.flags_ = setFlag(this.flags_, ComputedValue.isRunningSetterMask_, newValue);
1735
+ }
1736
+ }, {
1737
+ key: "isBeingObserved",
1738
+ get: function get() {
1739
+ return getFlag(this.flags_, ComputedValue.isBeingObservedMask_);
1740
+ },
1741
+ set: function set(newValue) {
1742
+ this.flags_ = setFlag(this.flags_, ComputedValue.isBeingObservedMask_, newValue);
1743
+ }
1744
+ }, {
1745
+ key: "isPendingUnobservation",
1746
+ get: function get() {
1747
+ return getFlag(this.flags_, ComputedValue.isPendingUnobservationMask_);
1748
+ },
1749
+ set: function set(newValue) {
1750
+ this.flags_ = setFlag(this.flags_, ComputedValue.isPendingUnobservationMask_, newValue);
1751
+ }
1752
+ }]);
1706
1753
  return ComputedValue;
1707
1754
  }();
1755
+ ComputedValue.isComputingMask_ = 1;
1756
+ ComputedValue.isRunningSetterMask_ = 2;
1757
+ ComputedValue.isBeingObservedMask_ = 4;
1758
+ ComputedValue.isPendingUnobservationMask_ = 8;
1708
1759
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1709
1760
 
1710
1761
  var IDerivationState_;
@@ -2106,9 +2157,9 @@
2106
2157
  }
2107
2158
 
2108
2159
  function queueForUnobservation(observable) {
2109
- if (observable.isPendingUnobservation_ === false) {
2160
+ if (observable.isPendingUnobservation === false) {
2110
2161
  // invariant(observable._observers.length === 0, "INTERNAL ERROR, should only queue for unobservation unobserved observables");
2111
- observable.isPendingUnobservation_ = true;
2162
+ observable.isPendingUnobservation = true;
2112
2163
  globalState.pendingUnobservations.push(observable);
2113
2164
  }
2114
2165
  }
@@ -2127,11 +2178,11 @@
2127
2178
  var list = globalState.pendingUnobservations;
2128
2179
  for (var i = 0; i < list.length; i++) {
2129
2180
  var observable = list[i];
2130
- observable.isPendingUnobservation_ = false;
2181
+ observable.isPendingUnobservation = false;
2131
2182
  if (observable.observers_.size === 0) {
2132
- if (observable.isBeingObserved_) {
2183
+ if (observable.isBeingObserved) {
2133
2184
  // if this observable had reactive observers, trigger the hooks
2134
- observable.isBeingObserved_ = false;
2185
+ observable.isBeingObserved = false;
2135
2186
  observable.onBUO();
2136
2187
  }
2137
2188
  if (observable instanceof ComputedValue) {
@@ -2157,12 +2208,12 @@
2157
2208
  observable.lastAccessedBy_ = derivation.runId_;
2158
2209
  // Tried storing newObserving, or observing, or both as Set, but performance didn't come close...
2159
2210
  derivation.newObserving_[derivation.unboundDepsCount_++] = observable;
2160
- if (!observable.isBeingObserved_ && globalState.trackingContext) {
2161
- observable.isBeingObserved_ = true;
2211
+ if (!observable.isBeingObserved && globalState.trackingContext) {
2212
+ observable.isBeingObserved = true;
2162
2213
  observable.onBO();
2163
2214
  }
2164
2215
  }
2165
- return observable.isBeingObserved_;
2216
+ return observable.isBeingObserved;
2166
2217
  } else if (observable.observers_.size === 0 && globalState.inBatch > 0) {
2167
2218
  queueForUnobservation(observable);
2168
2219
  }
@@ -4287,7 +4338,7 @@
4287
4338
  return _this5.set(key, value);
4288
4339
  });
4289
4340
  } else if (isES6Map(other)) {
4290
- if (other.constructor !== Map) {
4341
+ if (!isPlainES6Map(other)) {
4291
4342
  die(19, other);
4292
4343
  }
4293
4344
  other.forEach(function (value, key) {