mobx 6.11.0-pre → 6.12.0

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.
@@ -422,7 +422,7 @@
422
422
  }
423
423
  function assert20223DecoratorType(context, types) {
424
424
  if ( !types.includes(context.kind)) {
425
- die("Decorator may not be used like this");
425
+ die("The decorator applied to '" + String(context.name) + "' cannot be used on a " + context.kind + " element");
426
426
  }
427
427
  }
428
428
 
@@ -442,14 +442,12 @@
442
442
  this.isPendingUnobservation_ = false;
443
443
  this.isBeingObserved_ = false;
444
444
  this.observers_ = new Set();
445
- this.batchId_ = void 0;
446
445
  this.diffValue_ = 0;
447
446
  this.lastAccessedBy_ = 0;
448
447
  this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
449
448
  this.onBOL = void 0;
450
449
  this.onBUOL = void 0;
451
450
  this.name_ = name_;
452
- this.batchId_ = globalState.inBatch ? globalState.batchId : NaN;
453
451
  }
454
452
  // onBecomeObservedListeners
455
453
  var _proto = Atom.prototype;
@@ -478,13 +476,6 @@
478
476
  * Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
479
477
  */;
480
478
  _proto.reportChanged = function reportChanged() {
481
- if (!globalState.inBatch || this.batchId_ !== globalState.batchId) {
482
- // We could update state version only at the end of batch,
483
- // but we would still have to switch some global flag here to signal a change.
484
- globalState.stateVersion = globalState.stateVersion < Number.MAX_SAFE_INTEGER ? globalState.stateVersion + 1 : Number.MIN_SAFE_INTEGER;
485
- // Avoids the possibility of hitting the same globalState.batchId when it cycled through all integers (necessary?)
486
- this.batchId_ = NaN;
487
- }
488
479
  startBatch();
489
480
  propagateChanged(this);
490
481
  endBatch();
@@ -920,24 +911,21 @@
920
911
  }
921
912
  function decorate_20223_$4(desc, context) {
922
913
  {
923
- assert20223DecoratorType(context, ["accessor", "field"]);
914
+ if (context.kind === "field") {
915
+ throw die("Please use `@observable accessor " + String(context.name) + "` instead of `@observable " + String(context.name) + "`");
916
+ }
917
+ assert20223DecoratorType(context, ["accessor"]);
924
918
  }
925
919
  var ann = this;
926
920
  var kind = context.kind,
927
- name = context.name,
928
- addInitializer = context.addInitializer;
929
- // Backwards/Legacy behavior, expects makeObservable(this)
930
- if (kind == "field") {
931
- addInitializer(function () {
932
- storeAnnotation(this, name, ann);
933
- });
934
- return;
935
- }
921
+ name = context.name;
936
922
  // The laziness here is not ideal... It's a workaround to how 2022.3 Decorators are implemented:
937
923
  // `addInitializer` callbacks are executed _before_ any accessors are defined (instead of the ideal-for-us right after each).
938
924
  // This means that, if we were to do our stuff in an `addInitializer`, we'd attempt to read a private slot
939
925
  // before it has been initialized. The runtime doesn't like that and throws a `Cannot read private member
940
926
  // from an object whose class did not declare it` error.
927
+ // TODO: it seems that this will not be required anymore in the final version of the spec
928
+ // See TODO: link
941
929
  var initializedObjects = new WeakSet();
942
930
  function initializeObservable(target, value) {
943
931
  var _ann$options_$enhance, _ann$options_;
@@ -1240,6 +1228,9 @@
1240
1228
  return executeAction(actionName, autoAction, fn, ref || this, arguments);
1241
1229
  }
1242
1230
  res.isMobxAction = true;
1231
+ res.toString = function () {
1232
+ return fn.toString();
1233
+ };
1243
1234
  if (isFunctionNameConfigurable) {
1244
1235
  tmpNameDescriptor.value = actionName;
1245
1236
  defineProperty(res, "name", tmpNameDescriptor);
@@ -1987,7 +1978,6 @@
1987
1978
  this.runId = 0;
1988
1979
  this.mobxGuid = 0;
1989
1980
  this.inBatch = 0;
1990
- this.batchId = Number.MIN_SAFE_INTEGER;
1991
1981
  this.pendingUnobservations = [];
1992
1982
  this.pendingReactions = [];
1993
1983
  this.isRunningReactions = false;
@@ -2004,7 +1994,6 @@
2004
1994
  this.useProxies = true;
2005
1995
  this.verifyProxies = false;
2006
1996
  this.safeDescriptors = true;
2007
- this.stateVersion = Number.MIN_SAFE_INTEGER;
2008
1997
  };
2009
1998
  var canMergeGlobalState = true;
2010
1999
  var isolateCalled = false;
@@ -2127,9 +2116,6 @@
2127
2116
  * Avoids unnecessary recalculations.
2128
2117
  */
2129
2118
  function startBatch() {
2130
- if (globalState.inBatch === 0) {
2131
- globalState.batchId = globalState.batchId < Number.MAX_SAFE_INTEGER ? globalState.batchId + 1 : Number.MIN_SAFE_INTEGER;
2132
- }
2133
2119
  globalState.inBatch++;
2134
2120
  }
2135
2121
  function endBatch() {
@@ -3966,6 +3952,7 @@
3966
3952
  * Without this, everything works as well, but this works
3967
3953
  * faster as everything works on unproxied values
3968
3954
  */
3955
+ addArrayExtension("at", simpleFunc);
3969
3956
  addArrayExtension("concat", simpleFunc);
3970
3957
  addArrayExtension("flat", simpleFunc);
3971
3958
  addArrayExtension("includes", simpleFunc);
@@ -3975,15 +3962,21 @@
3975
3962
  addArrayExtension("slice", simpleFunc);
3976
3963
  addArrayExtension("toString", simpleFunc);
3977
3964
  addArrayExtension("toLocaleString", simpleFunc);
3965
+ addArrayExtension("toSorted", simpleFunc);
3966
+ addArrayExtension("toSpliced", simpleFunc);
3967
+ addArrayExtension("with", simpleFunc);
3978
3968
  // map
3979
3969
  addArrayExtension("every", mapLikeFunc);
3980
3970
  addArrayExtension("filter", mapLikeFunc);
3981
3971
  addArrayExtension("find", mapLikeFunc);
3982
3972
  addArrayExtension("findIndex", mapLikeFunc);
3973
+ addArrayExtension("findLast", mapLikeFunc);
3974
+ addArrayExtension("findLastIndex", mapLikeFunc);
3983
3975
  addArrayExtension("flatMap", mapLikeFunc);
3984
3976
  addArrayExtension("forEach", mapLikeFunc);
3985
3977
  addArrayExtension("map", mapLikeFunc);
3986
3978
  addArrayExtension("some", mapLikeFunc);
3979
+ addArrayExtension("toReversed", mapLikeFunc);
3987
3980
  // reduce
3988
3981
  addArrayExtension("reduce", reduceLikeFunc);
3989
3982
  addArrayExtension("reduceRight", reduceLikeFunc);