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