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.
package/dist/mobx.esm.js CHANGED
@@ -204,10 +204,16 @@ function createInstanceofPredicate(name, theClass) {
204
204
  };
205
205
  }
206
206
  function isES6Map(thing) {
207
- return thing instanceof Map;
207
+ return thing != null && Object.prototype.toString.call(thing) === "[object Map]";
208
+ }
209
+ function isPlainES6Map(thing) {
210
+ var mapProto = Object.getPrototypeOf(thing);
211
+ var objectProto = Object.getPrototypeOf(mapProto);
212
+ var nullProto = Object.getPrototypeOf(objectProto);
213
+ return nullProto === null;
208
214
  }
209
215
  function isES6Set(thing) {
210
- return thing instanceof Set;
216
+ return thing != null && Object.prototype.toString.call(thing) === "[object Set]";
211
217
  }
212
218
  var hasGetOwnPropertySymbols = typeof Object.getOwnPropertySymbols !== "undefined";
213
219
  /**
@@ -434,8 +440,8 @@ var Atom = /*#__PURE__*/function () {
434
440
  name_ = process.env.NODE_ENV !== "production" ? "Atom@" + getNextId() : "Atom";
435
441
  }
436
442
  this.name_ = void 0;
437
- this.isPendingUnobservation_ = false;
438
- this.isBeingObserved_ = false;
443
+ this.isPendingUnobservation = false;
444
+ this.isBeingObserved = false;
439
445
  this.observers_ = new Set();
440
446
  this.diffValue_ = 0;
441
447
  this.lastAccessedBy_ = 0;
@@ -1458,6 +1464,17 @@ var ObservableValue = /*#__PURE__*/function (_Atom) {
1458
1464
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1459
1465
 
1460
1466
  var _Symbol$toPrimitive$1;
1467
+ function getFlag(flags, mask) {
1468
+ return !!(flags & mask);
1469
+ }
1470
+ function setFlag(flags, mask, newValue) {
1471
+ if (newValue) {
1472
+ flags |= mask;
1473
+ } else {
1474
+ flags &= ~mask;
1475
+ }
1476
+ return flags;
1477
+ }
1461
1478
  /**
1462
1479
  * A node in the state dependency root that observes other nodes, and can be observed itself.
1463
1480
  *
@@ -1482,8 +1499,6 @@ var ComputedValue = /*#__PURE__*/function () {
1482
1499
  // nodes we are looking at. Our value depends on these nodes
1483
1500
  // during tracking it's an array with new observed observers
1484
1501
 
1485
- // to check for cycles
1486
-
1487
1502
  // N.B: unminified as it is used by MST
1488
1503
 
1489
1504
  /**
@@ -1502,8 +1517,6 @@ var ComputedValue = /*#__PURE__*/function () {
1502
1517
  this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
1503
1518
  this.observing_ = [];
1504
1519
  this.newObserving_ = null;
1505
- this.isBeingObserved_ = false;
1506
- this.isPendingUnobservation_ = false;
1507
1520
  this.observers_ = new Set();
1508
1521
  this.diffValue_ = 0;
1509
1522
  this.runId_ = 0;
@@ -1513,8 +1526,7 @@ var ComputedValue = /*#__PURE__*/function () {
1513
1526
  this.value_ = new CaughtException(null);
1514
1527
  this.name_ = void 0;
1515
1528
  this.triggeredBy_ = void 0;
1516
- this.isComputing_ = false;
1517
- this.isRunningSetter_ = false;
1529
+ this.flags_ = 0;
1518
1530
  this.derivation = void 0;
1519
1531
  this.setter_ = void 0;
1520
1532
  this.isTracing_ = TraceMode.NONE;
@@ -1555,12 +1567,14 @@ var ComputedValue = /*#__PURE__*/function () {
1555
1567
  });
1556
1568
  }
1557
1569
  }
1570
+ // to check for cycles
1571
+ ;
1558
1572
  /**
1559
1573
  * Returns the current value of this computed value.
1560
1574
  * Will evaluate its computation first if needed.
1561
- */;
1575
+ */
1562
1576
  _proto.get = function get() {
1563
- if (this.isComputing_) {
1577
+ if (this.isComputing) {
1564
1578
  die(32, this.name_, this.derivation);
1565
1579
  }
1566
1580
  if (globalState.inBatch === 0 &&
@@ -1593,14 +1607,14 @@ var ComputedValue = /*#__PURE__*/function () {
1593
1607
  };
1594
1608
  _proto.set = function set(value) {
1595
1609
  if (this.setter_) {
1596
- if (this.isRunningSetter_) {
1610
+ if (this.isRunningSetter) {
1597
1611
  die(33, this.name_);
1598
1612
  }
1599
- this.isRunningSetter_ = true;
1613
+ this.isRunningSetter = true;
1600
1614
  try {
1601
1615
  this.setter_.call(this.scope_, value);
1602
1616
  } finally {
1603
- this.isRunningSetter_ = false;
1617
+ this.isRunningSetter = false;
1604
1618
  }
1605
1619
  } else {
1606
1620
  die(34, this.name_);
@@ -1628,7 +1642,7 @@ var ComputedValue = /*#__PURE__*/function () {
1628
1642
  return changed;
1629
1643
  };
1630
1644
  _proto.computeValue_ = function computeValue_(track) {
1631
- this.isComputing_ = true;
1645
+ this.isComputing = true;
1632
1646
  // don't allow state changes during computation
1633
1647
  var prev = allowStateChangesStart(false);
1634
1648
  var res;
@@ -1646,7 +1660,7 @@ var ComputedValue = /*#__PURE__*/function () {
1646
1660
  }
1647
1661
  }
1648
1662
  allowStateChangesEnd(prev);
1649
- this.isComputing_ = false;
1663
+ this.isComputing = false;
1650
1664
  return res;
1651
1665
  };
1652
1666
  _proto.suspend_ = function suspend_() {
@@ -1701,8 +1715,45 @@ var ComputedValue = /*#__PURE__*/function () {
1701
1715
  _proto[_Symbol$toPrimitive$1] = function () {
1702
1716
  return this.valueOf();
1703
1717
  };
1718
+ _createClass(ComputedValue, [{
1719
+ key: "isComputing",
1720
+ get: function get() {
1721
+ return getFlag(this.flags_, ComputedValue.isComputingMask_);
1722
+ },
1723
+ set: function set(newValue) {
1724
+ this.flags_ = setFlag(this.flags_, ComputedValue.isComputingMask_, newValue);
1725
+ }
1726
+ }, {
1727
+ key: "isRunningSetter",
1728
+ get: function get() {
1729
+ return getFlag(this.flags_, ComputedValue.isRunningSetterMask_);
1730
+ },
1731
+ set: function set(newValue) {
1732
+ this.flags_ = setFlag(this.flags_, ComputedValue.isRunningSetterMask_, newValue);
1733
+ }
1734
+ }, {
1735
+ key: "isBeingObserved",
1736
+ get: function get() {
1737
+ return getFlag(this.flags_, ComputedValue.isBeingObservedMask_);
1738
+ },
1739
+ set: function set(newValue) {
1740
+ this.flags_ = setFlag(this.flags_, ComputedValue.isBeingObservedMask_, newValue);
1741
+ }
1742
+ }, {
1743
+ key: "isPendingUnobservation",
1744
+ get: function get() {
1745
+ return getFlag(this.flags_, ComputedValue.isPendingUnobservationMask_);
1746
+ },
1747
+ set: function set(newValue) {
1748
+ this.flags_ = setFlag(this.flags_, ComputedValue.isPendingUnobservationMask_, newValue);
1749
+ }
1750
+ }]);
1704
1751
  return ComputedValue;
1705
1752
  }();
1753
+ ComputedValue.isComputingMask_ = 1;
1754
+ ComputedValue.isRunningSetterMask_ = 2;
1755
+ ComputedValue.isBeingObservedMask_ = 4;
1756
+ ComputedValue.isPendingUnobservationMask_ = 8;
1706
1757
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1707
1758
 
1708
1759
  var IDerivationState_;
@@ -2110,9 +2161,9 @@ function removeObserver(observable, node) {
2110
2161
  }
2111
2162
 
2112
2163
  function queueForUnobservation(observable) {
2113
- if (observable.isPendingUnobservation_ === false) {
2164
+ if (observable.isPendingUnobservation === false) {
2114
2165
  // invariant(observable._observers.length === 0, "INTERNAL ERROR, should only queue for unobservation unobserved observables");
2115
- observable.isPendingUnobservation_ = true;
2166
+ observable.isPendingUnobservation = true;
2116
2167
  globalState.pendingUnobservations.push(observable);
2117
2168
  }
2118
2169
  }
@@ -2131,11 +2182,11 @@ function endBatch() {
2131
2182
  var list = globalState.pendingUnobservations;
2132
2183
  for (var i = 0; i < list.length; i++) {
2133
2184
  var observable = list[i];
2134
- observable.isPendingUnobservation_ = false;
2185
+ observable.isPendingUnobservation = false;
2135
2186
  if (observable.observers_.size === 0) {
2136
- if (observable.isBeingObserved_) {
2187
+ if (observable.isBeingObserved) {
2137
2188
  // if this observable had reactive observers, trigger the hooks
2138
- observable.isBeingObserved_ = false;
2189
+ observable.isBeingObserved = false;
2139
2190
  observable.onBUO();
2140
2191
  }
2141
2192
  if (observable instanceof ComputedValue) {
@@ -2161,12 +2212,12 @@ function reportObserved(observable) {
2161
2212
  observable.lastAccessedBy_ = derivation.runId_;
2162
2213
  // Tried storing newObserving, or observing, or both as Set, but performance didn't come close...
2163
2214
  derivation.newObserving_[derivation.unboundDepsCount_++] = observable;
2164
- if (!observable.isBeingObserved_ && globalState.trackingContext) {
2165
- observable.isBeingObserved_ = true;
2215
+ if (!observable.isBeingObserved && globalState.trackingContext) {
2216
+ observable.isBeingObserved = true;
2166
2217
  observable.onBO();
2167
2218
  }
2168
2219
  }
2169
- return observable.isBeingObserved_;
2220
+ return observable.isBeingObserved;
2170
2221
  } else if (observable.observers_.size === 0 && globalState.inBatch > 0) {
2171
2222
  queueForUnobservation(observable);
2172
2223
  }
@@ -4306,7 +4357,7 @@ var ObservableMap = /*#__PURE__*/function () {
4306
4357
  return _this5.set(key, value);
4307
4358
  });
4308
4359
  } else if (isES6Map(other)) {
4309
- if (other.constructor !== Map) {
4360
+ if (!isPlainES6Map(other)) {
4310
4361
  die(19, other);
4311
4362
  }
4312
4363
  other.forEach(function (value, key) {