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.
@@ -422,7 +422,7 @@ function assertNotDecorated(prototype, annotation, key) {
422
422
  var fieldName = prototype.constructor.name + ".prototype." + key.toString();
423
423
  var currentAnnotationType = prototype[storedAnnotationsSymbol][key].annotationType_;
424
424
  var requestedAnnotationType = annotation.annotationType_;
425
- 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.");
425
+ 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.");
426
426
  }
427
427
  }
428
428
  /**
@@ -2314,7 +2314,7 @@ function reportObserved(observable) {
2314
2314
  }
2315
2315
  }
2316
2316
 
2317
- return true;
2317
+ return observable.isBeingObserved_;
2318
2318
  } else if (observable.observers_.size === 0 && globalState.inBatch > 0) {
2319
2319
  queueForUnobservation(observable);
2320
2320
  }
@@ -3681,12 +3681,25 @@ function _when(predicate, effect, opts) {
3681
3681
  }
3682
3682
 
3683
3683
  function whenPromise(predicate, opts) {
3684
+ var _opts$signal;
3685
+
3684
3686
  if ( opts && opts.onError) {
3685
3687
  return die("the options 'onError' and 'promise' cannot be combined");
3686
3688
  }
3687
3689
 
3690
+ if (opts != null && (_opts$signal = opts.signal) != null && _opts$signal.aborted) {
3691
+ return Object.assign(Promise.reject(new Error("WHEN_ABORTED")), {
3692
+ cancel: function cancel() {
3693
+ return null;
3694
+ }
3695
+ });
3696
+ }
3697
+
3688
3698
  var cancel;
3699
+ var abort;
3689
3700
  var res = new Promise(function (resolve, reject) {
3701
+ var _opts$signal2;
3702
+
3690
3703
  var disposer = _when(predicate, resolve, _extends({}, opts, {
3691
3704
  onError: reject
3692
3705
  }));
@@ -3695,6 +3708,17 @@ function whenPromise(predicate, opts) {
3695
3708
  disposer();
3696
3709
  reject(new Error("WHEN_CANCELLED"));
3697
3710
  };
3711
+
3712
+ abort = function abort() {
3713
+ disposer();
3714
+ reject(new Error("WHEN_ABORTED"));
3715
+ };
3716
+
3717
+ opts == null ? void 0 : (_opts$signal2 = opts.signal) == null ? void 0 : _opts$signal2.addEventListener("abort", abort);
3718
+ })["finally"](function () {
3719
+ var _opts$signal3;
3720
+
3721
+ return opts == null ? void 0 : (_opts$signal3 = opts.signal) == null ? void 0 : _opts$signal3.removeEventListener("abort", abort);
3698
3722
  });
3699
3723
  res.cancel = cancel;
3700
3724
  return res;
@@ -4213,17 +4237,23 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
4213
4237
  };
4214
4238
 
4215
4239
  _proto.get_ = function get_(index) {
4216
- if (index < this.values_.length) {
4217
- this.atom_.reportObserved();
4218
- return this.dehanceValue_(this.values_[index]);
4240
+ if (this.legacyMode_ && index >= this.values_.length) {
4241
+ console.warn( "[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" );
4242
+ return undefined;
4219
4243
  }
4220
4244
 
4221
- console.warn( "[mobx] Out of bounds read: " + index );
4245
+ this.atom_.reportObserved();
4246
+ return this.dehanceValue_(this.values_[index]);
4222
4247
  };
4223
4248
 
4224
4249
  _proto.set_ = function set_(index, newValue) {
4225
4250
  var values = this.values_;
4226
4251
 
4252
+ if (this.legacyMode_ && index > values.length) {
4253
+ // out of bounds
4254
+ die(17, index, values.length);
4255
+ }
4256
+
4227
4257
  if (index < values.length) {
4228
4258
  // update at index in range
4229
4259
  checkIfStateModificationsAreAllowed(this.atom_);
@@ -4251,12 +4281,19 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
4251
4281
  values[index] = newValue;
4252
4282
  this.notifyArrayChildUpdate_(index, newValue, oldValue);
4253
4283
  }
4254
- } else if (index === values.length) {
4255
- // add a new item
4256
- this.spliceWithArray_(index, 0, [newValue]);
4257
4284
  } else {
4258
- // out of bounds
4259
- die(17, index, values.length);
4285
+ // For out of bound index, we don't create an actual sparse array,
4286
+ // but rather fill the holes with undefined (same as setArrayLength_).
4287
+ // This could be considered a bug.
4288
+ var newItems = new Array(index + 1 - values.length);
4289
+
4290
+ for (var i = 0; i < newItems.length - 1; i++) {
4291
+ newItems[i] = undefined;
4292
+ } // No Array.fill everywhere...
4293
+
4294
+
4295
+ newItems[newItems.length - 1] = newValue;
4296
+ this.spliceWithArray_(values.length, 0, newItems);
4260
4297
  }
4261
4298
  };
4262
4299
 
@@ -5983,16 +6020,18 @@ function assertAnnotable(adm, annotation, key) {
5983
6020
  var fieldName = adm.name_ + "." + key.toString();
5984
6021
  var currentAnnotationType = adm.appliedAnnotations_[key].annotationType_;
5985
6022
  var requestedAnnotationType = annotation.annotationType_;
5986
- 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.");
6023
+ 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.");
5987
6024
  }
5988
6025
  }
5989
6026
 
6027
+ var ENTRY_0 = /*#__PURE__*/createArrayEntryDescriptor(0);
5990
6028
  /**
5991
6029
  * This array buffer contains two lists of properties, so that all arrays
5992
6030
  * can recycle their property definitions, which significantly improves performance of creating
5993
6031
  * properties on the fly.
5994
6032
  */
5995
6033
 
6034
+
5996
6035
  var OBSERVABLE_ARRAY_BUFFER_SIZE = 0; // Typescript workaround to make sure ObservableArray extends Array
5997
6036
 
5998
6037
  var StubArray = function StubArray() {};
@@ -6038,6 +6077,12 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
6038
6077
  allowStateChangesEnd(prev);
6039
6078
  }
6040
6079
 
6080
+ {
6081
+ // Seems that Safari won't use numeric prototype setter untill any * numeric property is
6082
+ // defined on the instance. After that it works fine, even if this property is deleted.
6083
+ Object.defineProperty(_assertThisInitialized(_this), "0", ENTRY_0);
6084
+ }
6085
+
6041
6086
  return _this;
6042
6087
  }
6043
6088