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.
@@ -677,7 +677,7 @@
677
677
 
678
678
  function createActionDescriptor(adm, annotation, key, descriptor, // provides ability to disable safeDescriptors for prototypes
679
679
  safeDescriptors) {
680
- var _annotation$options_, _annotation$options_$, _annotation$options_2, _annotation$options_$2, _annotation$options_3;
680
+ var _annotation$options_, _annotation$options_$, _annotation$options_2, _annotation$options_$2, _annotation$options_3, _annotation$options_4, _adm$proxy_2;
681
681
 
682
682
  if (safeDescriptors === void 0) {
683
683
  safeDescriptors = globalState.safeDescriptors;
@@ -693,7 +693,8 @@
693
693
  }
694
694
 
695
695
  return {
696
- 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),
696
+ 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
697
+ ((_annotation$options_4 = annotation.options_) == null ? void 0 : _annotation$options_4.bound) ? (_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_ : undefined),
697
698
  // Non-configurable for classes
698
699
  // prevents accidental field redefinition in subclass
699
700
  configurable: safeDescriptors ? adm.isPlainObject_ : true,
@@ -1540,22 +1541,21 @@
1540
1541
  /* see #1208 */
1541
1542
  this.dependenciesState_ === IDerivationState_.NOT_TRACKING_;
1542
1543
  var newValue = this.computeValue_(true);
1543
-
1544
- if ( isSpyEnabled()) {
1545
- spyReport({
1546
- observableKind: "computed",
1547
- debugObjectName: this.name_,
1548
- object: this.scope_,
1549
- type: "update",
1550
- oldValue: this.value_,
1551
- newValue: newValue
1552
- });
1553
- }
1554
-
1555
1544
  var changed = wasSuspended || isCaughtException(oldValue) || isCaughtException(newValue) || !this.equals_(oldValue, newValue);
1556
1545
 
1557
1546
  if (changed) {
1558
1547
  this.value_ = newValue;
1548
+
1549
+ if ( isSpyEnabled()) {
1550
+ spyReport({
1551
+ observableKind: "computed",
1552
+ debugObjectName: this.name_,
1553
+ object: this.scope_,
1554
+ type: "update",
1555
+ oldValue: oldValue,
1556
+ newValue: newValue
1557
+ });
1558
+ }
1559
1559
  }
1560
1560
 
1561
1561
  return changed;
@@ -1974,6 +1974,8 @@
1974
1974
  if (global.__mobxGlobals && global.__mobxGlobals.version !== new MobXGlobals().version) canMergeGlobalState = false;
1975
1975
 
1976
1976
  if (!canMergeGlobalState) {
1977
+ // Because this is a IIFE we need to let isolateCalled a chance to change
1978
+ // so we run it after the event loop completed at least 1 iteration
1977
1979
  setTimeout(function () {
1978
1980
  if (!isolateCalled) {
1979
1981
  die(35);
@@ -2221,8 +2223,7 @@
2221
2223
  return;
2222
2224
  }
2223
2225
 
2224
- lines.push("" + new Array(depth).join("\t") + tree.name); // MWE: not the fastest, but the easiest way :)
2225
-
2226
+ lines.push("" + "\t".repeat(depth - 1) + tree.name);
2226
2227
  if (tree.dependencies) tree.dependencies.forEach(function (child) {
2227
2228
  return printDepTree(child, lines, depth + 1);
2228
2229
  });
@@ -2653,8 +2654,7 @@
2653
2654
  var firstTime = true;
2654
2655
  var isScheduled = false;
2655
2656
  var value;
2656
- var oldValue = undefined; // only an issue with fireImmediately
2657
-
2657
+ var oldValue;
2658
2658
  var equals = opts.compareStructural ? comparer.structural : opts.equals || comparer["default"];
2659
2659
  var r = new Reaction(name, function () {
2660
2660
  if (firstTime || runSync) {
@@ -2770,7 +2770,7 @@
2770
2770
  if (arguments.length > 4) die("'extendObservable' expected 2-4 arguments");
2771
2771
  if (typeof target !== "object") die("'extendObservable' expects an object as first argument");
2772
2772
  if (isObservableMap(target)) die("'extendObservable' should not be used on maps, use map.merge instead");
2773
- if (!isPlainObject(properties)) die("'extendObservabe' only accepts plain objects as second argument");
2773
+ if (!isPlainObject(properties)) die("'extendObservable' only accepts plain objects as second argument");
2774
2774
  if (isObservable(properties) || isObservable(annotations)) die("Extending an object with another observable (object) is not supported");
2775
2775
  } // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
2776
2776
 
@@ -2961,14 +2961,14 @@
2961
2961
  }
2962
2962
 
2963
2963
  function _isComputed(value, property) {
2964
- if (property !== undefined) {
2965
- if (isObservableObject(value) === false) return false;
2966
- if (!value[$mobx].values_.has(property)) return false;
2967
- var atom = getAtom(value, property);
2968
- return isComputedValue(atom);
2964
+ if (property === undefined) {
2965
+ return isComputedValue(value);
2969
2966
  }
2970
2967
 
2971
- return isComputedValue(value);
2968
+ if (isObservableObject(value) === false) return false;
2969
+ if (!value[$mobx].values_.has(property)) return false;
2970
+ var atom = getAtom(value, property);
2971
+ return isComputedValue(atom);
2972
2972
  }
2973
2973
  function isComputed(value) {
2974
2974
  if ( arguments.length > 1) return die("isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property");
@@ -3327,7 +3327,7 @@
3327
3327
 
3328
3328
  cancel = function cancel() {
3329
3329
  disposer();
3330
- reject("WHEN_CANCELLED");
3330
+ reject(new Error("WHEN_CANCELLED"));
3331
3331
  };
3332
3332
  });
3333
3333
  res.cancel = cancel;
@@ -3458,7 +3458,11 @@
3458
3458
  try {
3459
3459
  var _annotations;
3460
3460
 
3461
- // Default to decorators
3461
+ if ("development" !== "production" && annotations && target[storedAnnotationsSymbol]) {
3462
+ die("makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.");
3463
+ } // Default to decorators
3464
+
3465
+
3462
3466
  (_annotations = annotations) != null ? _annotations : annotations = collectStoredAnnotations(target); // Annotate
3463
3467
 
3464
3468
  ownKeys(annotations).forEach(function (key) {
@@ -3619,7 +3623,7 @@
3619
3623
  };
3620
3624
 
3621
3625
  _proto.setArrayLength_ = function setArrayLength_(newLength) {
3622
- if (typeof newLength !== "number" || newLength < 0) die("Out of range: " + newLength);
3626
+ if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) die("Out of range: " + newLength);
3623
3627
  var currentLength = this.values_.length;
3624
3628
  if (newLength === currentLength) return;else if (newLength > currentLength) {
3625
3629
  var newItems = new Array(newLength - currentLength);
@@ -4108,9 +4112,11 @@
4108
4112
 
4109
4113
  if ( notifySpy) spyReportStart(_change);
4110
4114
  transaction(function () {
4115
+ var _this2$hasMap_$get;
4116
+
4111
4117
  _this2.keysAtom_.reportChanged();
4112
4118
 
4113
- _this2.updateHasMapEntry_(key, false);
4119
+ (_this2$hasMap_$get = _this2.hasMap_.get(key)) == null ? void 0 : _this2$hasMap_$get.setNewValue_(false);
4114
4120
 
4115
4121
  var observable = _this2.data_.get(key);
4116
4122
 
@@ -4126,14 +4132,6 @@
4126
4132
  return false;
4127
4133
  };
4128
4134
 
4129
- _proto.updateHasMapEntry_ = function updateHasMapEntry_(key, value) {
4130
- var entry = this.hasMap_.get(key);
4131
-
4132
- if (entry) {
4133
- entry.setNewValue_(value);
4134
- }
4135
- };
4136
-
4137
4135
  _proto.updateValue_ = function updateValue_(key, newValue) {
4138
4136
  var observable = this.data_.get(key);
4139
4137
  newValue = observable.prepareNewValue_(newValue);
@@ -4162,13 +4160,15 @@
4162
4160
 
4163
4161
  checkIfStateModificationsAreAllowed(this.keysAtom_);
4164
4162
  transaction(function () {
4163
+ var _this3$hasMap_$get;
4164
+
4165
4165
  var observable = new ObservableValue(newValue, _this3.enhancer_, _this3.name_ + "." + stringifyKey(key) , false);
4166
4166
 
4167
4167
  _this3.data_.set(key, observable);
4168
4168
 
4169
4169
  newValue = observable.value_; // value might have been changed
4170
4170
 
4171
- _this3.updateHasMapEntry_(key, true);
4171
+ (_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(true);
4172
4172
 
4173
4173
  _this3.keysAtom_.reportChanged();
4174
4174
  });