mobx 6.6.1 → 6.7.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
@@ -424,7 +424,7 @@ function assertNotDecorated(prototype, annotation, key) {
424
424
  var fieldName = prototype.constructor.name + ".prototype." + key.toString();
425
425
  var currentAnnotationType = prototype[storedAnnotationsSymbol][key].annotationType_;
426
426
  var requestedAnnotationType = annotation.annotationType_;
427
- die("Cannot apply '@" + requestedAnnotationType + "' to '" + fieldName + "':" + ("\nThe field is already decorated with '@" + currentAnnotationType + "'.") + "\nRe-decorating fields is not allowed." + "\nUse '@override' decorator for methods overriden by subclass.");
427
+ die("Cannot apply '@" + requestedAnnotationType + "' to '" + fieldName + "':" + ("\nThe field is already decorated with '@" + currentAnnotationType + "'.") + "\nRe-decorating fields is not allowed." + "\nUse '@override' decorator for methods overridden by subclass.");
428
428
  }
429
429
  }
430
430
  /**
@@ -2325,7 +2325,7 @@ function reportObserved(observable) {
2325
2325
  }
2326
2326
  }
2327
2327
 
2328
- return true;
2328
+ return observable.isBeingObserved_;
2329
2329
  } else if (observable.observers_.size === 0 && globalState.inBatch > 0) {
2330
2330
  queueForUnobservation(observable);
2331
2331
  }
@@ -3707,12 +3707,25 @@ function _when(predicate, effect, opts) {
3707
3707
  }
3708
3708
 
3709
3709
  function whenPromise(predicate, opts) {
3710
+ var _opts$signal;
3711
+
3710
3712
  if (process.env.NODE_ENV !== "production" && opts && opts.onError) {
3711
3713
  return die("the options 'onError' and 'promise' cannot be combined");
3712
3714
  }
3713
3715
 
3716
+ if (opts != null && (_opts$signal = opts.signal) != null && _opts$signal.aborted) {
3717
+ return Object.assign(Promise.reject(new Error("WHEN_ABORTED")), {
3718
+ cancel: function cancel() {
3719
+ return null;
3720
+ }
3721
+ });
3722
+ }
3723
+
3714
3724
  var cancel;
3725
+ var abort;
3715
3726
  var res = new Promise(function (resolve, reject) {
3727
+ var _opts$signal2;
3728
+
3716
3729
  var disposer = _when(predicate, resolve, _extends({}, opts, {
3717
3730
  onError: reject
3718
3731
  }));
@@ -3721,6 +3734,17 @@ function whenPromise(predicate, opts) {
3721
3734
  disposer();
3722
3735
  reject(new Error("WHEN_CANCELLED"));
3723
3736
  };
3737
+
3738
+ abort = function abort() {
3739
+ disposer();
3740
+ reject(new Error("WHEN_ABORTED"));
3741
+ };
3742
+
3743
+ opts == null ? void 0 : (_opts$signal2 = opts.signal) == null ? void 0 : _opts$signal2.addEventListener("abort", abort);
3744
+ })["finally"](function () {
3745
+ var _opts$signal3;
3746
+
3747
+ return opts == null ? void 0 : (_opts$signal3 = opts.signal) == null ? void 0 : _opts$signal3.removeEventListener("abort", abort);
3724
3748
  });
3725
3749
  res.cancel = cancel;
3726
3750
  return res;
@@ -4239,17 +4263,23 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
4239
4263
  };
4240
4264
 
4241
4265
  _proto.get_ = function get_(index) {
4242
- if (index < this.values_.length) {
4243
- this.atom_.reportObserved();
4244
- return this.dehanceValue_(this.values_[index]);
4266
+ if (this.legacyMode_ && index >= this.values_.length) {
4267
+ console.warn(process.env.NODE_ENV !== "production" ? "[mobx.array] Attempt to read an array index (" + index + ") that is out of bounds (" + this.values_.length + "). Please check length first. Out of bound indices will not be tracked by MobX" : "[mobx] Out of bounds read: " + index);
4268
+ return undefined;
4245
4269
  }
4246
4270
 
4247
- console.warn(process.env.NODE_ENV !== "production" ? "[mobx] Out of bounds read: " + index : "[mobx.array] Attempt to read an array index (" + index + ") that is out of bounds (" + this.values_.length + "). Please check length first. Out of bound indices will not be tracked by MobX");
4271
+ this.atom_.reportObserved();
4272
+ return this.dehanceValue_(this.values_[index]);
4248
4273
  };
4249
4274
 
4250
4275
  _proto.set_ = function set_(index, newValue) {
4251
4276
  var values = this.values_;
4252
4277
 
4278
+ if (this.legacyMode_ && index > values.length) {
4279
+ // out of bounds
4280
+ die(17, index, values.length);
4281
+ }
4282
+
4253
4283
  if (index < values.length) {
4254
4284
  // update at index in range
4255
4285
  checkIfStateModificationsAreAllowed(this.atom_);
@@ -4277,12 +4307,19 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
4277
4307
  values[index] = newValue;
4278
4308
  this.notifyArrayChildUpdate_(index, newValue, oldValue);
4279
4309
  }
4280
- } else if (index === values.length) {
4281
- // add a new item
4282
- this.spliceWithArray_(index, 0, [newValue]);
4283
4310
  } else {
4284
- // out of bounds
4285
- die(17, index, values.length);
4311
+ // For out of bound index, we don't create an actual sparse array,
4312
+ // but rather fill the holes with undefined (same as setArrayLength_).
4313
+ // This could be considered a bug.
4314
+ var newItems = new Array(index + 1 - values.length);
4315
+
4316
+ for (var i = 0; i < newItems.length - 1; i++) {
4317
+ newItems[i] = undefined;
4318
+ } // No Array.fill everywhere...
4319
+
4320
+
4321
+ newItems[newItems.length - 1] = newValue;
4322
+ this.spliceWithArray_(values.length, 0, newItems);
4286
4323
  }
4287
4324
  };
4288
4325
 
@@ -6009,16 +6046,18 @@ function assertAnnotable(adm, annotation, key) {
6009
6046
  var fieldName = adm.name_ + "." + key.toString();
6010
6047
  var currentAnnotationType = adm.appliedAnnotations_[key].annotationType_;
6011
6048
  var requestedAnnotationType = annotation.annotationType_;
6012
- die("Cannot apply '" + requestedAnnotationType + "' to '" + fieldName + "':" + ("\nThe field is already annotated with '" + currentAnnotationType + "'.") + "\nRe-annotating fields is not allowed." + "\nUse 'override' annotation for methods overriden by subclass.");
6049
+ die("Cannot apply '" + requestedAnnotationType + "' to '" + fieldName + "':" + ("\nThe field is already annotated with '" + currentAnnotationType + "'.") + "\nRe-annotating fields is not allowed." + "\nUse 'override' annotation for methods overridden by subclass.");
6013
6050
  }
6014
6051
  }
6015
6052
 
6053
+ var ENTRY_0 = /*#__PURE__*/createArrayEntryDescriptor(0);
6016
6054
  /**
6017
6055
  * This array buffer contains two lists of properties, so that all arrays
6018
6056
  * can recycle their property definitions, which significantly improves performance of creating
6019
6057
  * properties on the fly.
6020
6058
  */
6021
6059
 
6060
+
6022
6061
  var OBSERVABLE_ARRAY_BUFFER_SIZE = 0; // Typescript workaround to make sure ObservableArray extends Array
6023
6062
 
6024
6063
  var StubArray = function StubArray() {};
@@ -6064,6 +6103,12 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
6064
6103
  allowStateChangesEnd(prev);
6065
6104
  }
6066
6105
 
6106
+ {
6107
+ // Seems that Safari won't use numeric prototype setter untill any * numeric property is
6108
+ // defined on the instance. After that it works fine, even if this property is deleted.
6109
+ Object.defineProperty(_assertThisInitialized(_this), "0", ENTRY_0);
6110
+ }
6111
+
6067
6112
  return _this;
6068
6113
  }
6069
6114