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.
package/dist/mobx.esm.js CHANGED
@@ -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