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.
@@ -2320,7 +2320,7 @@
2320
2320
  }
2321
2321
  }
2322
2322
 
2323
- return true;
2323
+ return observable.isBeingObserved_;
2324
2324
  } else if (observable.observers_.size === 0 && globalState.inBatch > 0) {
2325
2325
  queueForUnobservation(observable);
2326
2326
  }
@@ -3687,12 +3687,25 @@
3687
3687
  }
3688
3688
 
3689
3689
  function whenPromise(predicate, opts) {
3690
+ var _opts$signal;
3691
+
3690
3692
  if ( opts && opts.onError) {
3691
3693
  return die("the options 'onError' and 'promise' cannot be combined");
3692
3694
  }
3693
3695
 
3696
+ if (opts != null && (_opts$signal = opts.signal) != null && _opts$signal.aborted) {
3697
+ return Object.assign(Promise.reject(new Error("WHEN_ABORTED")), {
3698
+ cancel: function cancel() {
3699
+ return null;
3700
+ }
3701
+ });
3702
+ }
3703
+
3694
3704
  var cancel;
3705
+ var abort;
3695
3706
  var res = new Promise(function (resolve, reject) {
3707
+ var _opts$signal2;
3708
+
3696
3709
  var disposer = _when(predicate, resolve, _extends({}, opts, {
3697
3710
  onError: reject
3698
3711
  }));
@@ -3701,6 +3714,17 @@
3701
3714
  disposer();
3702
3715
  reject(new Error("WHEN_CANCELLED"));
3703
3716
  };
3717
+
3718
+ abort = function abort() {
3719
+ disposer();
3720
+ reject(new Error("WHEN_ABORTED"));
3721
+ };
3722
+
3723
+ opts == null ? void 0 : (_opts$signal2 = opts.signal) == null ? void 0 : _opts$signal2.addEventListener("abort", abort);
3724
+ })["finally"](function () {
3725
+ var _opts$signal3;
3726
+
3727
+ return opts == null ? void 0 : (_opts$signal3 = opts.signal) == null ? void 0 : _opts$signal3.removeEventListener("abort", abort);
3704
3728
  });
3705
3729
  res.cancel = cancel;
3706
3730
  return res;
@@ -4219,17 +4243,23 @@
4219
4243
  };
4220
4244
 
4221
4245
  _proto.get_ = function get_(index) {
4222
- if (index < this.values_.length) {
4223
- this.atom_.reportObserved();
4224
- return this.dehanceValue_(this.values_[index]);
4246
+ if (this.legacyMode_ && index >= this.values_.length) {
4247
+ 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" );
4248
+ return undefined;
4225
4249
  }
4226
4250
 
4227
- console.warn( "[mobx] Out of bounds read: " + index );
4251
+ this.atom_.reportObserved();
4252
+ return this.dehanceValue_(this.values_[index]);
4228
4253
  };
4229
4254
 
4230
4255
  _proto.set_ = function set_(index, newValue) {
4231
4256
  var values = this.values_;
4232
4257
 
4258
+ if (this.legacyMode_ && index > values.length) {
4259
+ // out of bounds
4260
+ die(17, index, values.length);
4261
+ }
4262
+
4233
4263
  if (index < values.length) {
4234
4264
  // update at index in range
4235
4265
  checkIfStateModificationsAreAllowed(this.atom_);
@@ -4257,12 +4287,19 @@
4257
4287
  values[index] = newValue;
4258
4288
  this.notifyArrayChildUpdate_(index, newValue, oldValue);
4259
4289
  }
4260
- } else if (index === values.length) {
4261
- // add a new item
4262
- this.spliceWithArray_(index, 0, [newValue]);
4263
4290
  } else {
4264
- // out of bounds
4265
- die(17, index, values.length);
4291
+ // For out of bound index, we don't create an actual sparse array,
4292
+ // but rather fill the holes with undefined (same as setArrayLength_).
4293
+ // This could be considered a bug.
4294
+ var newItems = new Array(index + 1 - values.length);
4295
+
4296
+ for (var i = 0; i < newItems.length - 1; i++) {
4297
+ newItems[i] = undefined;
4298
+ } // No Array.fill everywhere...
4299
+
4300
+
4301
+ newItems[newItems.length - 1] = newValue;
4302
+ this.spliceWithArray_(values.length, 0, newItems);
4266
4303
  }
4267
4304
  };
4268
4305