mobx 6.3.3 → 6.3.7

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.
@@ -671,7 +671,7 @@ function assertActionDescriptor(adm, _ref, key, _ref2) {
671
671
 
672
672
  function createActionDescriptor(adm, annotation, key, descriptor, // provides ability to disable safeDescriptors for prototypes
673
673
  safeDescriptors) {
674
- var _annotation$options_, _annotation$options_$, _annotation$options_2, _annotation$options_$2, _annotation$options_3;
674
+ var _annotation$options_, _annotation$options_$, _annotation$options_2, _annotation$options_$2, _annotation$options_3, _annotation$options_4, _adm$proxy_2;
675
675
 
676
676
  if (safeDescriptors === void 0) {
677
677
  safeDescriptors = globalState.safeDescriptors;
@@ -687,7 +687,8 @@ safeDescriptors) {
687
687
  }
688
688
 
689
689
  return {
690
- value: createAction((_annotation$options_$ = (_annotation$options_2 = annotation.options_) == null ? void 0 : _annotation$options_2.name) != null ? _annotation$options_$ : key.toString(), value, (_annotation$options_$2 = (_annotation$options_3 = annotation.options_) == null ? void 0 : _annotation$options_3.autoAction) != null ? _annotation$options_$2 : false),
690
+ value: createAction((_annotation$options_$ = (_annotation$options_2 = annotation.options_) == null ? void 0 : _annotation$options_2.name) != null ? _annotation$options_$ : key.toString(), value, (_annotation$options_$2 = (_annotation$options_3 = annotation.options_) == null ? void 0 : _annotation$options_3.autoAction) != null ? _annotation$options_$2 : false, // https://github.com/mobxjs/mobx/discussions/3140
691
+ ((_annotation$options_4 = annotation.options_) == null ? void 0 : _annotation$options_4.bound) ? (_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_ : undefined),
691
692
  // Non-configurable for classes
692
693
  // prevents accidental field redefinition in subclass
693
694
  configurable: safeDescriptors ? adm.isPlainObject_ : true,
@@ -1534,22 +1535,21 @@ var ComputedValue = /*#__PURE__*/function () {
1534
1535
  /* see #1208 */
1535
1536
  this.dependenciesState_ === IDerivationState_.NOT_TRACKING_;
1536
1537
  var newValue = this.computeValue_(true);
1537
-
1538
- if ( isSpyEnabled()) {
1539
- spyReport({
1540
- observableKind: "computed",
1541
- debugObjectName: this.name_,
1542
- object: this.scope_,
1543
- type: "update",
1544
- oldValue: this.value_,
1545
- newValue: newValue
1546
- });
1547
- }
1548
-
1549
1538
  var changed = wasSuspended || isCaughtException(oldValue) || isCaughtException(newValue) || !this.equals_(oldValue, newValue);
1550
1539
 
1551
1540
  if (changed) {
1552
1541
  this.value_ = newValue;
1542
+
1543
+ if ( isSpyEnabled()) {
1544
+ spyReport({
1545
+ observableKind: "computed",
1546
+ debugObjectName: this.name_,
1547
+ object: this.scope_,
1548
+ type: "update",
1549
+ oldValue: oldValue,
1550
+ newValue: newValue
1551
+ });
1552
+ }
1553
1553
  }
1554
1554
 
1555
1555
  return changed;
@@ -1968,6 +1968,8 @@ var globalState = /*#__PURE__*/function () {
1968
1968
  if (global.__mobxGlobals && global.__mobxGlobals.version !== new MobXGlobals().version) canMergeGlobalState = false;
1969
1969
 
1970
1970
  if (!canMergeGlobalState) {
1971
+ // Because this is a IIFE we need to let isolateCalled a chance to change
1972
+ // so we run it after the event loop completed at least 1 iteration
1971
1973
  setTimeout(function () {
1972
1974
  if (!isolateCalled) {
1973
1975
  die(35);
@@ -2215,8 +2217,7 @@ function printDepTree(tree, lines, depth) {
2215
2217
  return;
2216
2218
  }
2217
2219
 
2218
- lines.push("" + new Array(depth).join("\t") + tree.name); // MWE: not the fastest, but the easiest way :)
2219
-
2220
+ lines.push("" + "\t".repeat(depth - 1) + tree.name);
2220
2221
  if (tree.dependencies) tree.dependencies.forEach(function (child) {
2221
2222
  return printDepTree(child, lines, depth + 1);
2222
2223
  });
@@ -2647,8 +2648,7 @@ function reaction(expression, effect, opts) {
2647
2648
  var firstTime = true;
2648
2649
  var isScheduled = false;
2649
2650
  var value;
2650
- var oldValue = undefined; // only an issue with fireImmediately
2651
-
2651
+ var oldValue;
2652
2652
  var equals = opts.compareStructural ? comparer.structural : opts.equals || comparer["default"];
2653
2653
  var r = new Reaction(name, function () {
2654
2654
  if (firstTime || runSync) {
@@ -2764,7 +2764,7 @@ function extendObservable(target, properties, annotations, options) {
2764
2764
  if (arguments.length > 4) die("'extendObservable' expected 2-4 arguments");
2765
2765
  if (typeof target !== "object") die("'extendObservable' expects an object as first argument");
2766
2766
  if (isObservableMap(target)) die("'extendObservable' should not be used on maps, use map.merge instead");
2767
- if (!isPlainObject(properties)) die("'extendObservabe' only accepts plain objects as second argument");
2767
+ if (!isPlainObject(properties)) die("'extendObservable' only accepts plain objects as second argument");
2768
2768
  if (isObservable(properties) || isObservable(annotations)) die("Extending an object with another observable (object) is not supported");
2769
2769
  } // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
2770
2770
 
@@ -2955,14 +2955,14 @@ function interceptProperty(thing, property, handler) {
2955
2955
  }
2956
2956
 
2957
2957
  function _isComputed(value, property) {
2958
- if (property !== undefined) {
2959
- if (isObservableObject(value) === false) return false;
2960
- if (!value[$mobx].values_.has(property)) return false;
2961
- var atom = getAtom(value, property);
2962
- return isComputedValue(atom);
2958
+ if (property === undefined) {
2959
+ return isComputedValue(value);
2963
2960
  }
2964
2961
 
2965
- return isComputedValue(value);
2962
+ if (isObservableObject(value) === false) return false;
2963
+ if (!value[$mobx].values_.has(property)) return false;
2964
+ var atom = getAtom(value, property);
2965
+ return isComputedValue(atom);
2966
2966
  }
2967
2967
  function isComputed(value) {
2968
2968
  if ( arguments.length > 1) return die("isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property");
@@ -3321,7 +3321,7 @@ function whenPromise(predicate, opts) {
3321
3321
 
3322
3322
  cancel = function cancel() {
3323
3323
  disposer();
3324
- reject("WHEN_CANCELLED");
3324
+ reject(new Error("WHEN_CANCELLED"));
3325
3325
  };
3326
3326
  });
3327
3327
  res.cancel = cancel;
@@ -3452,7 +3452,11 @@ function makeObservable(target, annotations, options) {
3452
3452
  try {
3453
3453
  var _annotations;
3454
3454
 
3455
- // Default to decorators
3455
+ if ("development" !== "production" && annotations && target[storedAnnotationsSymbol]) {
3456
+ die("makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.");
3457
+ } // Default to decorators
3458
+
3459
+
3456
3460
  (_annotations = annotations) != null ? _annotations : annotations = collectStoredAnnotations(target); // Annotate
3457
3461
 
3458
3462
  ownKeys(annotations).forEach(function (key) {
@@ -3613,7 +3617,7 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
3613
3617
  };
3614
3618
 
3615
3619
  _proto.setArrayLength_ = function setArrayLength_(newLength) {
3616
- if (typeof newLength !== "number" || newLength < 0) die("Out of range: " + newLength);
3620
+ if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) die("Out of range: " + newLength);
3617
3621
  var currentLength = this.values_.length;
3618
3622
  if (newLength === currentLength) return;else if (newLength > currentLength) {
3619
3623
  var newItems = new Array(newLength - currentLength);
@@ -4102,9 +4106,11 @@ var ObservableMap = /*#__PURE__*/function () {
4102
4106
 
4103
4107
  if ( notifySpy) spyReportStart(_change);
4104
4108
  transaction(function () {
4109
+ var _this2$hasMap_$get;
4110
+
4105
4111
  _this2.keysAtom_.reportChanged();
4106
4112
 
4107
- _this2.updateHasMapEntry_(key, false);
4113
+ (_this2$hasMap_$get = _this2.hasMap_.get(key)) == null ? void 0 : _this2$hasMap_$get.setNewValue_(false);
4108
4114
 
4109
4115
  var observable = _this2.data_.get(key);
4110
4116
 
@@ -4120,14 +4126,6 @@ var ObservableMap = /*#__PURE__*/function () {
4120
4126
  return false;
4121
4127
  };
4122
4128
 
4123
- _proto.updateHasMapEntry_ = function updateHasMapEntry_(key, value) {
4124
- var entry = this.hasMap_.get(key);
4125
-
4126
- if (entry) {
4127
- entry.setNewValue_(value);
4128
- }
4129
- };
4130
-
4131
4129
  _proto.updateValue_ = function updateValue_(key, newValue) {
4132
4130
  var observable = this.data_.get(key);
4133
4131
  newValue = observable.prepareNewValue_(newValue);
@@ -4156,13 +4154,15 @@ var ObservableMap = /*#__PURE__*/function () {
4156
4154
 
4157
4155
  checkIfStateModificationsAreAllowed(this.keysAtom_);
4158
4156
  transaction(function () {
4157
+ var _this3$hasMap_$get;
4158
+
4159
4159
  var observable = new ObservableValue(newValue, _this3.enhancer_, _this3.name_ + "." + stringifyKey(key) , false);
4160
4160
 
4161
4161
  _this3.data_.set(key, observable);
4162
4162
 
4163
4163
  newValue = observable.value_; // value might have been changed
4164
4164
 
4165
- _this3.updateHasMapEntry_(key, true);
4165
+ (_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(true);
4166
4166
 
4167
4167
  _this3.keysAtom_.reportChanged();
4168
4168
  });