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.
package/dist/mobx.esm.js CHANGED
@@ -417,7 +417,7 @@ function is20223Decorator(context) {
417
417
  }
418
418
  function assert20223DecoratorType(context, types) {
419
419
  if (process.env.NODE_ENV !== "production" && !types.includes(context.kind)) {
420
- die("Decorator may not be used like this");
420
+ die("The decorator applied to '" + String(context.name) + "' cannot be used on a " + context.kind + " element");
421
421
  }
422
422
  }
423
423
 
@@ -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();
@@ -915,24 +906,21 @@ function extend_$4(adm, key, descriptor, proxyTrap) {
915
906
  }
916
907
  function decorate_20223_$4(desc, context) {
917
908
  if (process.env.NODE_ENV !== "production") {
918
- assert20223DecoratorType(context, ["accessor", "field"]);
909
+ if (context.kind === "field") {
910
+ throw die("Please use `@observable accessor " + String(context.name) + "` instead of `@observable " + String(context.name) + "`");
911
+ }
912
+ assert20223DecoratorType(context, ["accessor"]);
919
913
  }
920
914
  var ann = this;
921
915
  var kind = context.kind,
922
- name = context.name,
923
- addInitializer = context.addInitializer;
924
- // Backwards/Legacy behavior, expects makeObservable(this)
925
- if (kind == "field") {
926
- addInitializer(function () {
927
- storeAnnotation(this, name, ann);
928
- });
929
- return;
930
- }
916
+ name = context.name;
931
917
  // The laziness here is not ideal... It's a workaround to how 2022.3 Decorators are implemented:
932
918
  // `addInitializer` callbacks are executed _before_ any accessors are defined (instead of the ideal-for-us right after each).
933
919
  // This means that, if we were to do our stuff in an `addInitializer`, we'd attempt to read a private slot
934
920
  // before it has been initialized. The runtime doesn't like that and throws a `Cannot read private member
935
921
  // from an object whose class did not declare it` error.
922
+ // TODO: it seems that this will not be required anymore in the final version of the spec
923
+ // See TODO: link
936
924
  var initializedObjects = new WeakSet();
937
925
  function initializeObservable(target, value) {
938
926
  var _ann$options_$enhance, _ann$options_;
@@ -1235,6 +1223,9 @@ function createAction(actionName, fn, autoAction, ref) {
1235
1223
  return executeAction(actionName, autoAction, fn, ref || this, arguments);
1236
1224
  }
1237
1225
  res.isMobxAction = true;
1226
+ res.toString = function () {
1227
+ return fn.toString();
1228
+ };
1238
1229
  if (isFunctionNameConfigurable) {
1239
1230
  tmpNameDescriptor.value = actionName;
1240
1231
  defineProperty(res, "name", tmpNameDescriptor);
@@ -1991,7 +1982,6 @@ var MobXGlobals = function MobXGlobals() {
1991
1982
  this.runId = 0;
1992
1983
  this.mobxGuid = 0;
1993
1984
  this.inBatch = 0;
1994
- this.batchId = Number.MIN_SAFE_INTEGER;
1995
1985
  this.pendingUnobservations = [];
1996
1986
  this.pendingReactions = [];
1997
1987
  this.isRunningReactions = false;
@@ -2008,7 +1998,6 @@ var MobXGlobals = function MobXGlobals() {
2008
1998
  this.useProxies = true;
2009
1999
  this.verifyProxies = false;
2010
2000
  this.safeDescriptors = true;
2011
- this.stateVersion = Number.MIN_SAFE_INTEGER;
2012
2001
  };
2013
2002
  var canMergeGlobalState = true;
2014
2003
  var isolateCalled = false;
@@ -2131,9 +2120,6 @@ function queueForUnobservation(observable) {
2131
2120
  * Avoids unnecessary recalculations.
2132
2121
  */
2133
2122
  function startBatch() {
2134
- if (globalState.inBatch === 0) {
2135
- globalState.batchId = globalState.batchId < Number.MAX_SAFE_INTEGER ? globalState.batchId + 1 : Number.MIN_SAFE_INTEGER;
2136
- }
2137
2123
  globalState.inBatch++;
2138
2124
  }
2139
2125
  function endBatch() {
@@ -3985,6 +3971,7 @@ var arrayExtensions = {
3985
3971
  * Without this, everything works as well, but this works
3986
3972
  * faster as everything works on unproxied values
3987
3973
  */
3974
+ addArrayExtension("at", simpleFunc);
3988
3975
  addArrayExtension("concat", simpleFunc);
3989
3976
  addArrayExtension("flat", simpleFunc);
3990
3977
  addArrayExtension("includes", simpleFunc);
@@ -3994,15 +3981,21 @@ addArrayExtension("lastIndexOf", simpleFunc);
3994
3981
  addArrayExtension("slice", simpleFunc);
3995
3982
  addArrayExtension("toString", simpleFunc);
3996
3983
  addArrayExtension("toLocaleString", simpleFunc);
3984
+ addArrayExtension("toSorted", simpleFunc);
3985
+ addArrayExtension("toSpliced", simpleFunc);
3986
+ addArrayExtension("with", simpleFunc);
3997
3987
  // map
3998
3988
  addArrayExtension("every", mapLikeFunc);
3999
3989
  addArrayExtension("filter", mapLikeFunc);
4000
3990
  addArrayExtension("find", mapLikeFunc);
4001
3991
  addArrayExtension("findIndex", mapLikeFunc);
3992
+ addArrayExtension("findLast", mapLikeFunc);
3993
+ addArrayExtension("findLastIndex", mapLikeFunc);
4002
3994
  addArrayExtension("flatMap", mapLikeFunc);
4003
3995
  addArrayExtension("forEach", mapLikeFunc);
4004
3996
  addArrayExtension("map", mapLikeFunc);
4005
3997
  addArrayExtension("some", mapLikeFunc);
3998
+ addArrayExtension("toReversed", mapLikeFunc);
4006
3999
  // reduce
4007
4000
  addArrayExtension("reduce", reduceLikeFunc);
4008
4001
  addArrayExtension("reduceRight", reduceLikeFunc);