mobx 6.11.0 → 6.12.1

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,23 @@
1
1
  # mobx
2
2
 
3
+ ## 6.12.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`620f78c7`](https://github.com/mobxjs/mobx/commit/620f78c74e66bc532a96e28b26fd2d0ed1b67d54) [#3812](https://github.com/mobxjs/mobx/pull/3812) Thanks [@barroij](https://github.com/barroij)! - Prevent `reaction` from heeping a Reference to the OldValue that would prevent GC.
8
+
9
+ * [`6111b093`](https://github.com/mobxjs/mobx/commit/6111b0939d0d3c0d46dc325ba6bbd5f740a161d3) [#3833](https://github.com/mobxjs/mobx/pull/3833) Thanks [@realyze](https://github.com/realyze)! - Reduce memory overhead of tracking dependencies
10
+
11
+ ## 6.12.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [`ec5db592`](https://github.com/mobxjs/mobx/commit/ec5db592d7756826c31e710b1c759d7e9406b153) [#3792](https://github.com/mobxjs/mobx/pull/3792) Thanks [@tonyraoul](https://github.com/tonyraoul)! - Improve observablearray proxy pefromance for es2023.array and es2022.array methods
16
+
17
+ ### Patch Changes
18
+
19
+ - [`86616c11`](https://github.com/mobxjs/mobx/commit/86616c11c108a511331eb05e55c08fc2c5a23f4d) [#3654](https://github.com/mobxjs/mobx/pull/3654) Thanks [@ahoisl](https://github.com/ahoisl)! - fix: action transparently forwards toString of underlying function
20
+
3
21
  ## 6.11.0
4
22
 
5
23
  ### Minor Changes
package/README.md CHANGED
@@ -23,36 +23,36 @@ 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 (\$3000+ total contribution):** <br/>
27
- <a href="https://mendix.com/"><img src="https://mobx.js.org/assets/mendix-logo.png" align="center" width="100" title="Mendix" alt="Mendix" /></a>
26
+ **🥇 Gold sponsors (\$2500+ total contribution):**
27
+
28
+ <br/>
28
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>
29
30
  <a href="https://www.getparallax.com/"><img src="https://mobx.js.org/assets/parallax.png" align="center" width="100" title="Parallax" alt="Parallax" /></a>
30
- <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>
31
31
  <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
+ <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>
32
33
  <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>
33
34
  <a href="https://www.codefirst.co.uk/"><img src="https://mobx.js.org/assets/codefirst.png" align="center" width="100" title="CodeFirst" alt="CodeFirst"/></a>
34
35
  <a href="https://modulz.app/"><img src="https://mobx.js.org/assets/modulz.png" align="center" width="100" title="Modulz" alt="Modulz"/></a>
35
36
  <a href="https://coinbase.com/"><img src="https://mobx.js.org/assets/coinbase.jpeg" align="center" width="100" title="Coinbase" alt="Coinbase" /></a>
36
37
  <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>
37
- <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>
38
+ <a href="https://mendix.com/"><img src="https://mobx.js.org/assets/mendix-logo.png" align="center" width="100" title="Mendix" alt="Mendix" /></a>
38
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>
39
-
40
- **🥈 Silver sponsors (\$100+ per month):**<br/>
41
-
40
+ <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>
42
41
  <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>
43
- <a href="https://upper.co/?utm_source=github_mobxjs_sponsorship&utm_medium=paid_acquisition&utm_campaign=sponsorship"><img src="https://mobx.js.org/assets/upper.png" align="center" width="100" title="UPPER" alt="UPPER"/></a>
44
- <a href="https://www.easeus.com/?utm_source=github_mobxjs_sponsorship&utm_medium=readme&utm_campaign=sponsorship"><img src="https://mobx.js.org/assets/easeus.png" align="center" width="100" title="EaseUS" alt="EaseUS"/></a>
45
-
46
- **🥉 Bronze sponsors (\$500+ total contributions):**<br/>
47
42
  <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>
48
- <a href="https://space307.com/?utm_source=sponsorship&utm_medium=mobx&utm_campaign=readme"><img src="https://mobx.js.org/assets/space307.png" align="center" width="100" title="Space307" alt="Space307"/></a>
43
+
44
+ **🥈 Silver sponsors (\$500+ total contributions):**<br/>
45
+
49
46
  <a href="https://mantro.net/jobs/warlock"><img src="https://mobx.js.org/assets/mantro.png" align="center" width="100" title="mantro GmbH" alt="mantro GmbH"></a>
47
+ <a href="https://www.xh.com/"><img src="https://mobx.js.org/assets/xh.png" align="center" width="100" title="Extremely Heavy" alt="Extremely Heavy" /></a>
50
48
  <a href="https://www.algolia.com/"><img src="https://mobx.js.org/assets/algolia.jpg" align="center" width="100" title="Algolia" alt="Algolia" /></a>
51
- <a href="https://talentplot.com/"><img src="https://mobx.js.org/assets/talentplot.png" align="center" width="100" title="talentplot" alt="talentplot"></a>
52
- <a href="https://careers.dazn.com/"><img src="https://mobx.js.org/assets/dazn.png" align="center" width="100" title="DAZN" alt="DAZN"></a>
49
+ <a href="https://space307.com/?utm_source=sponsorship&utm_medium=mobx&utm_campaign=readme"><img src="https://mobx.js.org/assets/space307.png" align="center" width="100" title="Space307" alt="Space307"/></a>
53
50
  <a href="https://blokt.com/"><img src="https://mobx.js.org/assets/blokt.jpg" align="center" width="100" title="Blokt" alt="Blokt"/></a>
51
+ <a href="https://upper.co/?utm_source=github_mobxjs_sponsorship&utm_medium=paid_acquisition&utm_campaign=sponsorship"><img src="https://mobx.js.org/assets/upper.png" align="center" width="100" title="UPPER" alt="UPPER"/></a>
52
+ <a href="https://careers.dazn.com/"><img src="https://mobx.js.org/assets/dazn.png" align="center" width="100" title="DAZN" alt="DAZN"></a>
53
+ <a href="https://talentplot.com/"><img src="https://mobx.js.org/assets/talentplot.png" align="center" width="100" title="talentplot" alt="talentplot"></a>
54
54
 
55
- ---
55
+ ## <a href="https://www.easeus.com/?utm_source=github_mobxjs_sponsorship&utm_medium=readme&utm_campaign=sponsorship"><img src="https://mobx.js.org/assets/easeus.png" align="center" width="100" title="EaseUS" alt="EaseUS"/></a>
56
56
 
57
57
  ## Introduction
58
58
 
@@ -106,26 +106,22 @@ So what does code that uses MobX look like?
106
106
  import React from "react"
107
107
  import ReactDOM from "react-dom"
108
108
  import { makeAutoObservable } from "mobx"
109
- import { observer } from "mobx-react"
109
+ import { observer } from "mobx-react-lite"
110
110
 
111
111
  // Model the application state.
112
- class Timer {
113
- secondsPassed = 0
114
-
115
- constructor() {
116
- makeAutoObservable(this)
117
- }
118
-
119
- increase() {
120
- this.secondsPassed += 1
121
- }
122
-
123
- reset() {
124
- this.secondsPassed = 0
125
- }
112
+ function createTimer() {
113
+ return makeAutoObservable({
114
+ secondsPassed: 0,
115
+ increase() {
116
+ this.secondsPassed += 1
117
+ },
118
+ reset() {
119
+ this.secondsPassed = 0
120
+ }
121
+ })
126
122
  }
127
123
 
128
- const myTimer = new Timer()
124
+ const myTimer = createTimer()
129
125
 
130
126
  // Build a "user interface" that uses the observable state.
131
127
  const TimerView = observer(({ timer }) => (
@@ -9,7 +9,6 @@ export declare class Atom implements IAtom {
9
9
  isPendingUnobservation_: boolean;
10
10
  isBeingObserved_: boolean;
11
11
  observers_: Set<IDerivation>;
12
- batchId_: number;
13
12
  diffValue_: number;
14
13
  lastAccessedBy_: number;
15
14
  lowestObserverState_: IDerivationState_;
@@ -37,11 +37,6 @@ export declare class MobXGlobals {
37
37
  * Are we in a batch block? (and how many of them)
38
38
  */
39
39
  inBatch: number;
40
- /**
41
- * ID of the latest batch. Used to suppress reportChanged of newly created atoms.
42
- * Note the value persists even after batch ended.
43
- */
44
- batchId: number;
45
40
  /**
46
41
  * Observables that don't have observers anymore, and are about to be
47
42
  * suspended, unless somebody else accesses it in the same batch
@@ -106,10 +101,6 @@ export declare class MobXGlobals {
106
101
  * configurable: true
107
102
  */
108
103
  safeDescriptors: boolean;
109
- /**
110
- * Changes with each state update, used by useSyncExternalStore
111
- */
112
- stateVersion: number;
113
104
  }
114
105
  export declare let globalState: MobXGlobals;
115
106
  export declare function isolateGlobalState(): void;
@@ -440,14 +440,12 @@ var Atom = /*#__PURE__*/function () {
440
440
  this.isPendingUnobservation_ = false;
441
441
  this.isBeingObserved_ = false;
442
442
  this.observers_ = new Set();
443
- this.batchId_ = void 0;
444
443
  this.diffValue_ = 0;
445
444
  this.lastAccessedBy_ = 0;
446
445
  this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
447
446
  this.onBOL = void 0;
448
447
  this.onBUOL = void 0;
449
448
  this.name_ = name_;
450
- this.batchId_ = globalState.inBatch ? globalState.batchId : NaN;
451
449
  }
452
450
  // onBecomeObservedListeners
453
451
  var _proto = Atom.prototype;
@@ -476,13 +474,6 @@ var Atom = /*#__PURE__*/function () {
476
474
  * Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
477
475
  */;
478
476
  _proto.reportChanged = function reportChanged() {
479
- if (!globalState.inBatch || this.batchId_ !== globalState.batchId) {
480
- // We could update state version only at the end of batch,
481
- // but we would still have to switch some global flag here to signal a change.
482
- globalState.stateVersion = globalState.stateVersion < Number.MAX_SAFE_INTEGER ? globalState.stateVersion + 1 : Number.MIN_SAFE_INTEGER;
483
- // Avoids the possibility of hitting the same globalState.batchId when it cycled through all integers (necessary?)
484
- this.batchId_ = NaN;
485
- }
486
477
  startBatch();
487
478
  propagateChanged(this);
488
479
  endBatch();
@@ -1235,6 +1226,9 @@ function createAction(actionName, fn, autoAction, ref) {
1235
1226
  return executeAction(actionName, autoAction, fn, ref || this, arguments);
1236
1227
  }
1237
1228
  res.isMobxAction = true;
1229
+ res.toString = function () {
1230
+ return fn.toString();
1231
+ };
1238
1232
  if (isFunctionNameConfigurable) {
1239
1233
  tmpNameDescriptor.value = actionName;
1240
1234
  defineProperty(res, "name", tmpNameDescriptor);
@@ -1826,10 +1820,12 @@ function checkIfStateReadsAreAllowed(observable) {
1826
1820
  */
1827
1821
  function trackDerivedFunction(derivation, f, context) {
1828
1822
  var prevAllowStateReads = allowStateReadsStart(true);
1829
- // pre allocate array allocation + room for variation in deps
1830
- // array will be trimmed by bindDependencies
1831
1823
  changeDependenciesStateTo0(derivation);
1832
- derivation.newObserving_ = new Array(derivation.observing_.length + 100);
1824
+ // Preallocate array; will be trimmed by bindDependencies.
1825
+ derivation.newObserving_ = new Array(
1826
+ // Reserve constant space for initial dependencies, dynamic space otherwise.
1827
+ // See https://github.com/mobxjs/mobx/pull/3833
1828
+ derivation.runId_ === 0 ? 100 : derivation.observing_.length);
1833
1829
  derivation.unboundDepsCount_ = 0;
1834
1830
  derivation.runId_ = ++globalState.runId;
1835
1831
  var prevTracking = globalState.trackingDerivation;
@@ -1982,7 +1978,6 @@ var MobXGlobals = function MobXGlobals() {
1982
1978
  this.runId = 0;
1983
1979
  this.mobxGuid = 0;
1984
1980
  this.inBatch = 0;
1985
- this.batchId = Number.MIN_SAFE_INTEGER;
1986
1981
  this.pendingUnobservations = [];
1987
1982
  this.pendingReactions = [];
1988
1983
  this.isRunningReactions = false;
@@ -1999,7 +1994,6 @@ var MobXGlobals = function MobXGlobals() {
1999
1994
  this.useProxies = true;
2000
1995
  this.verifyProxies = false;
2001
1996
  this.safeDescriptors = true;
2002
- this.stateVersion = Number.MIN_SAFE_INTEGER;
2003
1997
  };
2004
1998
  var canMergeGlobalState = true;
2005
1999
  var isolateCalled = false;
@@ -2122,9 +2116,6 @@ function queueForUnobservation(observable) {
2122
2116
  * Avoids unnecessary recalculations.
2123
2117
  */
2124
2118
  function startBatch() {
2125
- if (globalState.inBatch === 0) {
2126
- globalState.batchId = globalState.batchId < Number.MAX_SAFE_INTEGER ? globalState.batchId + 1 : Number.MIN_SAFE_INTEGER;
2127
- }
2128
2119
  globalState.inBatch++;
2129
2120
  }
2130
2121
  function endBatch() {
@@ -2675,7 +2666,6 @@ function reaction(expression, effect, opts) {
2675
2666
  var firstTime = true;
2676
2667
  var isScheduled = false;
2677
2668
  var value;
2678
- var oldValue;
2679
2669
  var equals = opts.compareStructural ? comparer.structural : opts.equals || comparer["default"];
2680
2670
  var r = new Reaction(name, function () {
2681
2671
  if (firstTime || runSync) {
@@ -2691,12 +2681,12 @@ function reaction(expression, effect, opts) {
2691
2681
  return;
2692
2682
  }
2693
2683
  var changed = false;
2684
+ var oldValue = value;
2694
2685
  r.track(function () {
2695
2686
  var nextValue = allowStateChanges(false, function () {
2696
2687
  return expression(r);
2697
2688
  });
2698
2689
  changed = firstTime || !equals(value, nextValue);
2699
- oldValue = value;
2700
2690
  value = nextValue;
2701
2691
  });
2702
2692
  if (firstTime && opts.fireImmediately) {
@@ -3961,6 +3951,7 @@ var arrayExtensions = {
3961
3951
  * Without this, everything works as well, but this works
3962
3952
  * faster as everything works on unproxied values
3963
3953
  */
3954
+ addArrayExtension("at", simpleFunc);
3964
3955
  addArrayExtension("concat", simpleFunc);
3965
3956
  addArrayExtension("flat", simpleFunc);
3966
3957
  addArrayExtension("includes", simpleFunc);
@@ -3970,15 +3961,21 @@ addArrayExtension("lastIndexOf", simpleFunc);
3970
3961
  addArrayExtension("slice", simpleFunc);
3971
3962
  addArrayExtension("toString", simpleFunc);
3972
3963
  addArrayExtension("toLocaleString", simpleFunc);
3964
+ addArrayExtension("toSorted", simpleFunc);
3965
+ addArrayExtension("toSpliced", simpleFunc);
3966
+ addArrayExtension("with", simpleFunc);
3973
3967
  // map
3974
3968
  addArrayExtension("every", mapLikeFunc);
3975
3969
  addArrayExtension("filter", mapLikeFunc);
3976
3970
  addArrayExtension("find", mapLikeFunc);
3977
3971
  addArrayExtension("findIndex", mapLikeFunc);
3972
+ addArrayExtension("findLast", mapLikeFunc);
3973
+ addArrayExtension("findLastIndex", mapLikeFunc);
3978
3974
  addArrayExtension("flatMap", mapLikeFunc);
3979
3975
  addArrayExtension("forEach", mapLikeFunc);
3980
3976
  addArrayExtension("map", mapLikeFunc);
3981
3977
  addArrayExtension("some", mapLikeFunc);
3978
+ addArrayExtension("toReversed", mapLikeFunc);
3982
3979
  // reduce
3983
3980
  addArrayExtension("reduce", reduceLikeFunc);
3984
3981
  addArrayExtension("reduceRight", reduceLikeFunc);
@@ -3996,7 +3993,7 @@ function simpleFunc(funcName) {
3996
3993
  return dehancedValues[funcName].apply(dehancedValues, arguments);
3997
3994
  };
3998
3995
  }
3999
- // Make sure callbacks recieve correct array arg #2326
3996
+ // Make sure callbacks receive correct array arg #2326
4000
3997
  function mapLikeFunc(funcName) {
4001
3998
  return function (callback, thisArg) {
4002
3999
  var _this2 = this;
@@ -4008,7 +4005,7 @@ function mapLikeFunc(funcName) {
4008
4005
  });
4009
4006
  };
4010
4007
  }
4011
- // Make sure callbacks recieve correct array arg #2326
4008
+ // Make sure callbacks receive correct array arg #2326
4012
4009
  function reduceLikeFunc(funcName) {
4013
4010
  return function () {
4014
4011
  var _this3 = this;
@@ -5341,7 +5338,7 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
5341
5338
  _this.spliceWithArray(0, 0, initialValues);
5342
5339
  }
5343
5340
  if (safariPrototypeSetterInheritanceBug) {
5344
- // Seems that Safari won't use numeric prototype setter untill any * numeric property is
5341
+ // Seems that Safari won't use numeric prototype setter until any * numeric property is
5345
5342
  // defined on the instance. After that it works fine, even if this property is deleted.
5346
5343
  Object.defineProperty(_assertThisInitialized(_this), "0", ENTRY_0);
5347
5344
  }