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.
@@ -416,7 +416,7 @@ function is20223Decorator(context) {
416
416
  }
417
417
  function assert20223DecoratorType(context, types) {
418
418
  if ( !types.includes(context.kind)) {
419
- die("Decorator may not be used like this");
419
+ die("The decorator applied to '" + String(context.name) + "' cannot be used on a " + context.kind + " element");
420
420
  }
421
421
  }
422
422
 
@@ -436,14 +436,12 @@ var Atom = /*#__PURE__*/function () {
436
436
  this.isPendingUnobservation_ = false;
437
437
  this.isBeingObserved_ = false;
438
438
  this.observers_ = new Set();
439
- this.batchId_ = void 0;
440
439
  this.diffValue_ = 0;
441
440
  this.lastAccessedBy_ = 0;
442
441
  this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
443
442
  this.onBOL = void 0;
444
443
  this.onBUOL = void 0;
445
444
  this.name_ = name_;
446
- this.batchId_ = globalState.inBatch ? globalState.batchId : NaN;
447
445
  }
448
446
  // onBecomeObservedListeners
449
447
  var _proto = Atom.prototype;
@@ -472,13 +470,6 @@ var Atom = /*#__PURE__*/function () {
472
470
  * Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
473
471
  */;
474
472
  _proto.reportChanged = function reportChanged() {
475
- if (!globalState.inBatch || this.batchId_ !== globalState.batchId) {
476
- // We could update state version only at the end of batch,
477
- // but we would still have to switch some global flag here to signal a change.
478
- globalState.stateVersion = globalState.stateVersion < Number.MAX_SAFE_INTEGER ? globalState.stateVersion + 1 : Number.MIN_SAFE_INTEGER;
479
- // Avoids the possibility of hitting the same globalState.batchId when it cycled through all integers (necessary?)
480
- this.batchId_ = NaN;
481
- }
482
473
  startBatch();
483
474
  propagateChanged(this);
484
475
  endBatch();
@@ -914,24 +905,21 @@ function extend_$4(adm, key, descriptor, proxyTrap) {
914
905
  }
915
906
  function decorate_20223_$4(desc, context) {
916
907
  {
917
- assert20223DecoratorType(context, ["accessor", "field"]);
908
+ if (context.kind === "field") {
909
+ throw die("Please use `@observable accessor " + String(context.name) + "` instead of `@observable " + String(context.name) + "`");
910
+ }
911
+ assert20223DecoratorType(context, ["accessor"]);
918
912
  }
919
913
  var ann = this;
920
914
  var kind = context.kind,
921
- name = context.name,
922
- addInitializer = context.addInitializer;
923
- // Backwards/Legacy behavior, expects makeObservable(this)
924
- if (kind == "field") {
925
- addInitializer(function () {
926
- storeAnnotation(this, name, ann);
927
- });
928
- return;
929
- }
915
+ name = context.name;
930
916
  // The laziness here is not ideal... It's a workaround to how 2022.3 Decorators are implemented:
931
917
  // `addInitializer` callbacks are executed _before_ any accessors are defined (instead of the ideal-for-us right after each).
932
918
  // This means that, if we were to do our stuff in an `addInitializer`, we'd attempt to read a private slot
933
919
  // before it has been initialized. The runtime doesn't like that and throws a `Cannot read private member
934
920
  // from an object whose class did not declare it` error.
921
+ // TODO: it seems that this will not be required anymore in the final version of the spec
922
+ // See TODO: link
935
923
  var initializedObjects = new WeakSet();
936
924
  function initializeObservable(target, value) {
937
925
  var _ann$options_$enhance, _ann$options_;
@@ -1234,6 +1222,9 @@ function createAction(actionName, fn, autoAction, ref) {
1234
1222
  return executeAction(actionName, autoAction, fn, ref || this, arguments);
1235
1223
  }
1236
1224
  res.isMobxAction = true;
1225
+ res.toString = function () {
1226
+ return fn.toString();
1227
+ };
1237
1228
  if (isFunctionNameConfigurable) {
1238
1229
  tmpNameDescriptor.value = actionName;
1239
1230
  defineProperty(res, "name", tmpNameDescriptor);
@@ -1981,7 +1972,6 @@ var MobXGlobals = function MobXGlobals() {
1981
1972
  this.runId = 0;
1982
1973
  this.mobxGuid = 0;
1983
1974
  this.inBatch = 0;
1984
- this.batchId = Number.MIN_SAFE_INTEGER;
1985
1975
  this.pendingUnobservations = [];
1986
1976
  this.pendingReactions = [];
1987
1977
  this.isRunningReactions = false;
@@ -1998,7 +1988,6 @@ var MobXGlobals = function MobXGlobals() {
1998
1988
  this.useProxies = true;
1999
1989
  this.verifyProxies = false;
2000
1990
  this.safeDescriptors = true;
2001
- this.stateVersion = Number.MIN_SAFE_INTEGER;
2002
1991
  };
2003
1992
  var canMergeGlobalState = true;
2004
1993
  var isolateCalled = false;
@@ -2121,9 +2110,6 @@ function queueForUnobservation(observable) {
2121
2110
  * Avoids unnecessary recalculations.
2122
2111
  */
2123
2112
  function startBatch() {
2124
- if (globalState.inBatch === 0) {
2125
- globalState.batchId = globalState.batchId < Number.MAX_SAFE_INTEGER ? globalState.batchId + 1 : Number.MIN_SAFE_INTEGER;
2126
- }
2127
2113
  globalState.inBatch++;
2128
2114
  }
2129
2115
  function endBatch() {
@@ -3960,6 +3946,7 @@ var arrayExtensions = {
3960
3946
  * Without this, everything works as well, but this works
3961
3947
  * faster as everything works on unproxied values
3962
3948
  */
3949
+ addArrayExtension("at", simpleFunc);
3963
3950
  addArrayExtension("concat", simpleFunc);
3964
3951
  addArrayExtension("flat", simpleFunc);
3965
3952
  addArrayExtension("includes", simpleFunc);
@@ -3969,15 +3956,21 @@ addArrayExtension("lastIndexOf", simpleFunc);
3969
3956
  addArrayExtension("slice", simpleFunc);
3970
3957
  addArrayExtension("toString", simpleFunc);
3971
3958
  addArrayExtension("toLocaleString", simpleFunc);
3959
+ addArrayExtension("toSorted", simpleFunc);
3960
+ addArrayExtension("toSpliced", simpleFunc);
3961
+ addArrayExtension("with", simpleFunc);
3972
3962
  // map
3973
3963
  addArrayExtension("every", mapLikeFunc);
3974
3964
  addArrayExtension("filter", mapLikeFunc);
3975
3965
  addArrayExtension("find", mapLikeFunc);
3976
3966
  addArrayExtension("findIndex", mapLikeFunc);
3967
+ addArrayExtension("findLast", mapLikeFunc);
3968
+ addArrayExtension("findLastIndex", mapLikeFunc);
3977
3969
  addArrayExtension("flatMap", mapLikeFunc);
3978
3970
  addArrayExtension("forEach", mapLikeFunc);
3979
3971
  addArrayExtension("map", mapLikeFunc);
3980
3972
  addArrayExtension("some", mapLikeFunc);
3973
+ addArrayExtension("toReversed", mapLikeFunc);
3981
3974
  // reduce
3982
3975
  addArrayExtension("reduce", reduceLikeFunc);
3983
3976
  addArrayExtension("reduceRight", reduceLikeFunc);