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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # mobx
2
2
 
3
+ ## 6.12.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [`ba890343`](https://github.com/mobxjs/mobx/commit/ba8903430ce96746db5dcde6b78edeb195ea8018) [#3893](https://github.com/mobxjs/mobx/pull/3893) Thanks [@g6123](https://github.com/g6123)! - Fix ES6 Map/Set checks for cross-window scripts
8
+
9
+ ## 6.12.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [`e9e1955f`](https://github.com/mobxjs/mobx/commit/e9e1955f745545d796d906b6e0ba04a6cde3f1ee) [#3880](https://github.com/mobxjs/mobx/pull/3880) Thanks [@peterm-canva](https://github.com/peterm-canva)! - Shrink ComputedValue using a bitfield
14
+
3
15
  ## 6.12.2
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -23,11 +23,16 @@ Documentation can be found at **[mobx.js.org](https://mobx.js.org/)**.
23
23
 
24
24
  MobX is made possible by the generosity of the sponsors below, and many other [individual backers](https://github.com/mobxjs/mobx/blob/main/docs/backers-sponsors.md#backers). Sponsoring directly impacts the longevity of this project.
25
25
 
26
- **🥇 Gold sponsors (\$2500+ total contribution):**
26
+ **🥇🥇 Platinum sponsors (\$5000+ total contribution): 🥇🥇**
27
27
 
28
28
  <br/>
29
29
  <a href="https://www.guilded.gg/"><img src="https://mobx.js.org/assets/guilded.jpg" align="center" width="100" title="Guilded" alt="Guilded" /></a>
30
+ <a href="https://www.canva.com/"><img src="https://mobx.js.org/assets/canva.svg" align="center" width="100" title="Canva" alt="Canva" /></a>
30
31
  <a href="https://www.getparallax.com/"><img src="https://mobx.js.org/assets/parallax.png" align="center" width="100" title="Parallax" alt="Parallax" /></a>
32
+
33
+ **🥇 Gold sponsors (\$2500+ total contribution):**
34
+
35
+ <br/>
31
36
  <a href="https://www.one-beyond.com"><img src="https://mobx.js.org/assets/dcsl.png" align="center" width="100" title="One Beyond" alt="One Beyond"/></a>
32
37
  <a href="https://frontendmasters.com/"><img src="https://mobx.js.org/assets/frontendmasters.jpg" align="center" width="100" title="Frontend Masters" alt="Frontend Masters"></a>
33
38
  <a href="http://auctionfrontier.com/"><img src="https://mobx.js.org/assets/auctionfrontier.jpeg" align="center" width="100" title="Auction Frontier" alt="Auction Frontier"></a>
@@ -36,7 +41,6 @@ MobX is made possible by the generosity of the sponsors below, and many other [i
36
41
  <a href="https://coinbase.com/"><img src="https://mobx.js.org/assets/coinbase.jpeg" align="center" width="100" title="Coinbase" alt="Coinbase" /></a>
37
42
  <a href="https://curology.com/blog/tech"><img src="https://mobx.js.org/assets/curology.png" align="center" width="100" title="Curology" alt="Curology"/></a>
38
43
  <a href="https://mendix.com/"><img src="https://mobx.js.org/assets/mendix-logo.png" align="center" width="100" title="Mendix" alt="Mendix" /></a>
39
- <a href="https://www.canva.com/"><img src="https://mobx.js.org/assets/canva.svg" align="center" width="100" title="Canva" alt="Canva" /></a>
40
44
  <a href="https://opensource.facebook.com/"><img src="https://mobx.js.org/assets/fbos.jpeg" align="center" width="100" title="Facebook Open Source" alt="Facebook Open Source" /></a>
41
45
  <a href="https://casinosites.ltd.uk/?utm_source=sponsorship&utm_medium=mobx&utm_campaign=readme"><img src="https://mobx.js.org/assets/casino2.png" align="center" width="100" title="Casino Sites" alt="Casino Sites"/></a>
42
46
  <a href="https://www.bugsnag.com/platforms/react-error-reporting?utm_source=MobX&utm_medium=Website&utm_content=open-source&utm_campaign=2019-community&utm_term=20190913"><img src="https://mobx.js.org/assets/bugsnag.jpg" align="center" width="100" title="Bugsnag" alt="Bugsnag"/></a>
@@ -32,5 +32,5 @@ export declare function has<T extends Object>(obj: T, key: string): boolean;
32
32
  export declare function get<K, V>(obj: ObservableMap<K, V>, key: K): V | undefined;
33
33
  export declare function get<T>(obj: IObservableArray<T>, index: number): T | undefined;
34
34
  export declare function get<T extends Object>(obj: T, key: string): any;
35
- export declare function apiDefineProperty(obj: Object, key: PropertyKey, descriptor: PropertyDescriptor): any;
36
- export declare function apiOwnKeys(obj: Object): any;
35
+ export declare function apiDefineProperty(obj: Object, key: PropertyKey, descriptor: PropertyDescriptor): boolean | null;
36
+ export declare function apiOwnKeys(obj: Object): (string | symbol)[];
@@ -6,8 +6,8 @@ export interface IAtom extends IObservable {
6
6
  }
7
7
  export declare class Atom implements IAtom {
8
8
  name_: string;
9
- isPendingUnobservation_: boolean;
10
- isBeingObserved_: boolean;
9
+ isPendingUnobservation: boolean;
10
+ isBeingObserved: boolean;
11
11
  observers_: Set<IDerivation>;
12
12
  diffValue_: number;
13
13
  lastAccessedBy_: number;
@@ -43,8 +43,6 @@ export declare class ComputedValue<T> implements IObservable, IComputedValue<T>,
43
43
  dependenciesState_: IDerivationState_;
44
44
  observing_: IObservable[];
45
45
  newObserving_: null;
46
- isBeingObserved_: boolean;
47
- isPendingUnobservation_: boolean;
48
46
  observers_: Set<IDerivation>;
49
47
  diffValue_: number;
50
48
  runId_: number;
@@ -54,8 +52,11 @@ export declare class ComputedValue<T> implements IObservable, IComputedValue<T>,
54
52
  protected value_: T | undefined | CaughtException;
55
53
  name_: string;
56
54
  triggeredBy_?: string;
57
- isComputing_: boolean;
58
- isRunningSetter_: boolean;
55
+ private static readonly isComputingMask_;
56
+ private static readonly isRunningSetterMask_;
57
+ private static readonly isBeingObservedMask_;
58
+ private static readonly isPendingUnobservationMask_;
59
+ private flags_;
59
60
  derivation: () => T;
60
61
  setter_?: (value: T) => void;
61
62
  isTracing_: TraceMode;
@@ -81,6 +82,14 @@ export declare class ComputedValue<T> implements IObservable, IComputedValue<T>,
81
82
  onBUOL: Set<Lambda> | undefined;
82
83
  onBO(): void;
83
84
  onBUO(): void;
85
+ private get isComputing();
86
+ private set isComputing(value);
87
+ private get isRunningSetter();
88
+ private set isRunningSetter(value);
89
+ get isBeingObserved(): boolean;
90
+ set isBeingObserved(newValue: boolean);
91
+ get isPendingUnobservation(): boolean;
92
+ set isPendingUnobservation(newValue: boolean);
84
93
  /**
85
94
  * Returns the current value of this computed value.
86
95
  * Will evaluate its computation first if needed.
@@ -11,9 +11,9 @@ export interface IObservable extends IDepTreeNode {
11
11
  * the dependency is already established
12
12
  */
13
13
  lastAccessedBy_: number;
14
- isBeingObserved_: boolean;
14
+ isBeingObserved: boolean;
15
15
  lowestObserverState_: IDerivationState_;
16
- isPendingUnobservation_: boolean;
16
+ isPendingUnobservation: boolean;
17
17
  observers_: Set<IDerivation>;
18
18
  onBUO(): void;
19
19
  onBO(): void;
@@ -207,10 +207,16 @@ function createInstanceofPredicate(name, theClass) {
207
207
  };
208
208
  }
209
209
  function isES6Map(thing) {
210
- return thing instanceof Map;
210
+ return thing != null && Object.prototype.toString.call(thing) === "[object Map]";
211
+ }
212
+ function isPlainES6Map(thing) {
213
+ var mapProto = Object.getPrototypeOf(thing);
214
+ var objectProto = Object.getPrototypeOf(mapProto);
215
+ var nullProto = Object.getPrototypeOf(objectProto);
216
+ return nullProto === null;
211
217
  }
212
218
  function isES6Set(thing) {
213
- return thing instanceof Set;
219
+ return thing != null && Object.prototype.toString.call(thing) === "[object Set]";
214
220
  }
215
221
  var hasGetOwnPropertySymbols = typeof Object.getOwnPropertySymbols !== "undefined";
216
222
  /**
@@ -437,8 +443,8 @@ var Atom = /*#__PURE__*/function () {
437
443
  name_ = "Atom@" + getNextId() ;
438
444
  }
439
445
  this.name_ = void 0;
440
- this.isPendingUnobservation_ = false;
441
- this.isBeingObserved_ = false;
446
+ this.isPendingUnobservation = false;
447
+ this.isBeingObserved = false;
442
448
  this.observers_ = new Set();
443
449
  this.diffValue_ = 0;
444
450
  this.lastAccessedBy_ = 0;
@@ -1461,6 +1467,17 @@ var ObservableValue = /*#__PURE__*/function (_Atom) {
1461
1467
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1462
1468
 
1463
1469
  var _Symbol$toPrimitive$1;
1470
+ function getFlag(flags, mask) {
1471
+ return !!(flags & mask);
1472
+ }
1473
+ function setFlag(flags, mask, newValue) {
1474
+ if (newValue) {
1475
+ flags |= mask;
1476
+ } else {
1477
+ flags &= ~mask;
1478
+ }
1479
+ return flags;
1480
+ }
1464
1481
  /**
1465
1482
  * A node in the state dependency root that observes other nodes, and can be observed itself.
1466
1483
  *
@@ -1485,8 +1502,6 @@ var ComputedValue = /*#__PURE__*/function () {
1485
1502
  // nodes we are looking at. Our value depends on these nodes
1486
1503
  // during tracking it's an array with new observed observers
1487
1504
 
1488
- // to check for cycles
1489
-
1490
1505
  // N.B: unminified as it is used by MST
1491
1506
 
1492
1507
  /**
@@ -1505,8 +1520,6 @@ var ComputedValue = /*#__PURE__*/function () {
1505
1520
  this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
1506
1521
  this.observing_ = [];
1507
1522
  this.newObserving_ = null;
1508
- this.isBeingObserved_ = false;
1509
- this.isPendingUnobservation_ = false;
1510
1523
  this.observers_ = new Set();
1511
1524
  this.diffValue_ = 0;
1512
1525
  this.runId_ = 0;
@@ -1516,8 +1529,7 @@ var ComputedValue = /*#__PURE__*/function () {
1516
1529
  this.value_ = new CaughtException(null);
1517
1530
  this.name_ = void 0;
1518
1531
  this.triggeredBy_ = void 0;
1519
- this.isComputing_ = false;
1520
- this.isRunningSetter_ = false;
1532
+ this.flags_ = 0;
1521
1533
  this.derivation = void 0;
1522
1534
  this.setter_ = void 0;
1523
1535
  this.isTracing_ = TraceMode.NONE;
@@ -1558,12 +1570,14 @@ var ComputedValue = /*#__PURE__*/function () {
1558
1570
  });
1559
1571
  }
1560
1572
  }
1573
+ // to check for cycles
1574
+ ;
1561
1575
  /**
1562
1576
  * Returns the current value of this computed value.
1563
1577
  * Will evaluate its computation first if needed.
1564
- */;
1578
+ */
1565
1579
  _proto.get = function get() {
1566
- if (this.isComputing_) {
1580
+ if (this.isComputing) {
1567
1581
  die(32, this.name_, this.derivation);
1568
1582
  }
1569
1583
  if (globalState.inBatch === 0 &&
@@ -1596,14 +1610,14 @@ var ComputedValue = /*#__PURE__*/function () {
1596
1610
  };
1597
1611
  _proto.set = function set(value) {
1598
1612
  if (this.setter_) {
1599
- if (this.isRunningSetter_) {
1613
+ if (this.isRunningSetter) {
1600
1614
  die(33, this.name_);
1601
1615
  }
1602
- this.isRunningSetter_ = true;
1616
+ this.isRunningSetter = true;
1603
1617
  try {
1604
1618
  this.setter_.call(this.scope_, value);
1605
1619
  } finally {
1606
- this.isRunningSetter_ = false;
1620
+ this.isRunningSetter = false;
1607
1621
  }
1608
1622
  } else {
1609
1623
  die(34, this.name_);
@@ -1631,7 +1645,7 @@ var ComputedValue = /*#__PURE__*/function () {
1631
1645
  return changed;
1632
1646
  };
1633
1647
  _proto.computeValue_ = function computeValue_(track) {
1634
- this.isComputing_ = true;
1648
+ this.isComputing = true;
1635
1649
  // don't allow state changes during computation
1636
1650
  var prev = allowStateChangesStart(false);
1637
1651
  var res;
@@ -1649,7 +1663,7 @@ var ComputedValue = /*#__PURE__*/function () {
1649
1663
  }
1650
1664
  }
1651
1665
  allowStateChangesEnd(prev);
1652
- this.isComputing_ = false;
1666
+ this.isComputing = false;
1653
1667
  return res;
1654
1668
  };
1655
1669
  _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_;
@@ -2104,9 +2155,9 @@ function removeObserver(observable, node) {
2104
2155
  }
2105
2156
 
2106
2157
  function queueForUnobservation(observable) {
2107
- if (observable.isPendingUnobservation_ === false) {
2158
+ if (observable.isPendingUnobservation === false) {
2108
2159
  // invariant(observable._observers.length === 0, "INTERNAL ERROR, should only queue for unobservation unobserved observables");
2109
- observable.isPendingUnobservation_ = true;
2160
+ observable.isPendingUnobservation = true;
2110
2161
  globalState.pendingUnobservations.push(observable);
2111
2162
  }
2112
2163
  }
@@ -2125,11 +2176,11 @@ function endBatch() {
2125
2176
  var list = globalState.pendingUnobservations;
2126
2177
  for (var i = 0; i < list.length; i++) {
2127
2178
  var observable = list[i];
2128
- observable.isPendingUnobservation_ = false;
2179
+ observable.isPendingUnobservation = false;
2129
2180
  if (observable.observers_.size === 0) {
2130
- if (observable.isBeingObserved_) {
2181
+ if (observable.isBeingObserved) {
2131
2182
  // if this observable had reactive observers, trigger the hooks
2132
- observable.isBeingObserved_ = false;
2183
+ observable.isBeingObserved = false;
2133
2184
  observable.onBUO();
2134
2185
  }
2135
2186
  if (observable instanceof ComputedValue) {
@@ -2155,12 +2206,12 @@ function reportObserved(observable) {
2155
2206
  observable.lastAccessedBy_ = derivation.runId_;
2156
2207
  // Tried storing newObserving, or observing, or both as Set, but performance didn't come close...
2157
2208
  derivation.newObserving_[derivation.unboundDepsCount_++] = observable;
2158
- if (!observable.isBeingObserved_ && globalState.trackingContext) {
2159
- observable.isBeingObserved_ = true;
2209
+ if (!observable.isBeingObserved && globalState.trackingContext) {
2210
+ observable.isBeingObserved = true;
2160
2211
  observable.onBO();
2161
2212
  }
2162
2213
  }
2163
- return observable.isBeingObserved_;
2214
+ return observable.isBeingObserved;
2164
2215
  } else if (observable.observers_.size === 0 && globalState.inBatch > 0) {
2165
2216
  queueForUnobservation(observable);
2166
2217
  }
@@ -4285,7 +4336,7 @@ var ObservableMap = /*#__PURE__*/function () {
4285
4336
  return _this5.set(key, value);
4286
4337
  });
4287
4338
  } else if (isES6Map(other)) {
4288
- if (other.constructor !== Map) {
4339
+ if (!isPlainES6Map(other)) {
4289
4340
  die(19, other);
4290
4341
  }
4291
4342
  other.forEach(function (value, key) {