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/dist/mobx.esm.js CHANGED
@@ -437,14 +437,12 @@ var Atom = /*#__PURE__*/function () {
437
437
  this.isPendingUnobservation_ = false;
438
438
  this.isBeingObserved_ = false;
439
439
  this.observers_ = new Set();
440
- this.batchId_ = void 0;
441
440
  this.diffValue_ = 0;
442
441
  this.lastAccessedBy_ = 0;
443
442
  this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
444
443
  this.onBOL = void 0;
445
444
  this.onBUOL = void 0;
446
445
  this.name_ = name_;
447
- this.batchId_ = globalState.inBatch ? globalState.batchId : NaN;
448
446
  }
449
447
  // onBecomeObservedListeners
450
448
  var _proto = Atom.prototype;
@@ -473,13 +471,6 @@ var Atom = /*#__PURE__*/function () {
473
471
  * Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
474
472
  */;
475
473
  _proto.reportChanged = function reportChanged() {
476
- if (!globalState.inBatch || this.batchId_ !== globalState.batchId) {
477
- // We could update state version only at the end of batch,
478
- // but we would still have to switch some global flag here to signal a change.
479
- globalState.stateVersion = globalState.stateVersion < Number.MAX_SAFE_INTEGER ? globalState.stateVersion + 1 : Number.MIN_SAFE_INTEGER;
480
- // Avoids the possibility of hitting the same globalState.batchId when it cycled through all integers (necessary?)
481
- this.batchId_ = NaN;
482
- }
483
474
  startBatch();
484
475
  propagateChanged(this);
485
476
  endBatch();
@@ -1232,6 +1223,9 @@ function createAction(actionName, fn, autoAction, ref) {
1232
1223
  return executeAction(actionName, autoAction, fn, ref || this, arguments);
1233
1224
  }
1234
1225
  res.isMobxAction = true;
1226
+ res.toString = function () {
1227
+ return fn.toString();
1228
+ };
1235
1229
  if (isFunctionNameConfigurable) {
1236
1230
  tmpNameDescriptor.value = actionName;
1237
1231
  defineProperty(res, "name", tmpNameDescriptor);
@@ -1829,10 +1823,12 @@ function checkIfStateReadsAreAllowed(observable) {
1829
1823
  */
1830
1824
  function trackDerivedFunction(derivation, f, context) {
1831
1825
  var prevAllowStateReads = allowStateReadsStart(true);
1832
- // pre allocate array allocation + room for variation in deps
1833
- // array will be trimmed by bindDependencies
1834
1826
  changeDependenciesStateTo0(derivation);
1835
- derivation.newObserving_ = new Array(derivation.observing_.length + 100);
1827
+ // Preallocate array; will be trimmed by bindDependencies.
1828
+ derivation.newObserving_ = new Array(
1829
+ // Reserve constant space for initial dependencies, dynamic space otherwise.
1830
+ // See https://github.com/mobxjs/mobx/pull/3833
1831
+ derivation.runId_ === 0 ? 100 : derivation.observing_.length);
1836
1832
  derivation.unboundDepsCount_ = 0;
1837
1833
  derivation.runId_ = ++globalState.runId;
1838
1834
  var prevTracking = globalState.trackingDerivation;
@@ -1988,7 +1984,6 @@ var MobXGlobals = function MobXGlobals() {
1988
1984
  this.runId = 0;
1989
1985
  this.mobxGuid = 0;
1990
1986
  this.inBatch = 0;
1991
- this.batchId = Number.MIN_SAFE_INTEGER;
1992
1987
  this.pendingUnobservations = [];
1993
1988
  this.pendingReactions = [];
1994
1989
  this.isRunningReactions = false;
@@ -2005,7 +2000,6 @@ var MobXGlobals = function MobXGlobals() {
2005
2000
  this.useProxies = true;
2006
2001
  this.verifyProxies = false;
2007
2002
  this.safeDescriptors = true;
2008
- this.stateVersion = Number.MIN_SAFE_INTEGER;
2009
2003
  };
2010
2004
  var canMergeGlobalState = true;
2011
2005
  var isolateCalled = false;
@@ -2128,9 +2122,6 @@ function queueForUnobservation(observable) {
2128
2122
  * Avoids unnecessary recalculations.
2129
2123
  */
2130
2124
  function startBatch() {
2131
- if (globalState.inBatch === 0) {
2132
- globalState.batchId = globalState.batchId < Number.MAX_SAFE_INTEGER ? globalState.batchId + 1 : Number.MIN_SAFE_INTEGER;
2133
- }
2134
2125
  globalState.inBatch++;
2135
2126
  }
2136
2127
  function endBatch() {
@@ -2693,7 +2684,6 @@ function reaction(expression, effect, opts) {
2693
2684
  var firstTime = true;
2694
2685
  var isScheduled = false;
2695
2686
  var value;
2696
- var oldValue;
2697
2687
  var equals = opts.compareStructural ? comparer.structural : opts.equals || comparer["default"];
2698
2688
  var r = new Reaction(name, function () {
2699
2689
  if (firstTime || runSync) {
@@ -2709,12 +2699,12 @@ function reaction(expression, effect, opts) {
2709
2699
  return;
2710
2700
  }
2711
2701
  var changed = false;
2702
+ var oldValue = value;
2712
2703
  r.track(function () {
2713
2704
  var nextValue = allowStateChanges(false, function () {
2714
2705
  return expression(r);
2715
2706
  });
2716
2707
  changed = firstTime || !equals(value, nextValue);
2717
- oldValue = value;
2718
2708
  value = nextValue;
2719
2709
  });
2720
2710
  if (firstTime && opts.fireImmediately) {
@@ -3982,6 +3972,7 @@ var arrayExtensions = {
3982
3972
  * Without this, everything works as well, but this works
3983
3973
  * faster as everything works on unproxied values
3984
3974
  */
3975
+ addArrayExtension("at", simpleFunc);
3985
3976
  addArrayExtension("concat", simpleFunc);
3986
3977
  addArrayExtension("flat", simpleFunc);
3987
3978
  addArrayExtension("includes", simpleFunc);
@@ -3991,15 +3982,21 @@ addArrayExtension("lastIndexOf", simpleFunc);
3991
3982
  addArrayExtension("slice", simpleFunc);
3992
3983
  addArrayExtension("toString", simpleFunc);
3993
3984
  addArrayExtension("toLocaleString", simpleFunc);
3985
+ addArrayExtension("toSorted", simpleFunc);
3986
+ addArrayExtension("toSpliced", simpleFunc);
3987
+ addArrayExtension("with", simpleFunc);
3994
3988
  // map
3995
3989
  addArrayExtension("every", mapLikeFunc);
3996
3990
  addArrayExtension("filter", mapLikeFunc);
3997
3991
  addArrayExtension("find", mapLikeFunc);
3998
3992
  addArrayExtension("findIndex", mapLikeFunc);
3993
+ addArrayExtension("findLast", mapLikeFunc);
3994
+ addArrayExtension("findLastIndex", mapLikeFunc);
3999
3995
  addArrayExtension("flatMap", mapLikeFunc);
4000
3996
  addArrayExtension("forEach", mapLikeFunc);
4001
3997
  addArrayExtension("map", mapLikeFunc);
4002
3998
  addArrayExtension("some", mapLikeFunc);
3999
+ addArrayExtension("toReversed", mapLikeFunc);
4003
4000
  // reduce
4004
4001
  addArrayExtension("reduce", reduceLikeFunc);
4005
4002
  addArrayExtension("reduceRight", reduceLikeFunc);
@@ -4017,7 +4014,7 @@ function simpleFunc(funcName) {
4017
4014
  return dehancedValues[funcName].apply(dehancedValues, arguments);
4018
4015
  };
4019
4016
  }
4020
- // Make sure callbacks recieve correct array arg #2326
4017
+ // Make sure callbacks receive correct array arg #2326
4021
4018
  function mapLikeFunc(funcName) {
4022
4019
  return function (callback, thisArg) {
4023
4020
  var _this2 = this;
@@ -4029,7 +4026,7 @@ function mapLikeFunc(funcName) {
4029
4026
  });
4030
4027
  };
4031
4028
  }
4032
- // Make sure callbacks recieve correct array arg #2326
4029
+ // Make sure callbacks receive correct array arg #2326
4033
4030
  function reduceLikeFunc(funcName) {
4034
4031
  return function () {
4035
4032
  var _this3 = this;
@@ -5362,7 +5359,7 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
5362
5359
  _this.spliceWithArray(0, 0, initialValues);
5363
5360
  }
5364
5361
  if (safariPrototypeSetterInheritanceBug) {
5365
- // Seems that Safari won't use numeric prototype setter untill any * numeric property is
5362
+ // Seems that Safari won't use numeric prototype setter until any * numeric property is
5366
5363
  // defined on the instance. After that it works fine, even if this property is deleted.
5367
5364
  Object.defineProperty(_assertThisInitialized(_this), "0", ENTRY_0);
5368
5365
  }