mobx 6.6.2 → 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.
@@ -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