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.
@@ -428,7 +428,7 @@
428
428
  var fieldName = prototype.constructor.name + ".prototype." + key.toString();
429
429
  var currentAnnotationType = prototype[storedAnnotationsSymbol][key].annotationType_;
430
430
  var requestedAnnotationType = annotation.annotationType_;
431
- 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.");
431
+ 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.");
432
432
  }
433
433
  }
434
434
  /**
@@ -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
 
@@ -5989,16 +6026,18 @@
5989
6026
  var fieldName = adm.name_ + "." + key.toString();
5990
6027
  var currentAnnotationType = adm.appliedAnnotations_[key].annotationType_;
5991
6028
  var requestedAnnotationType = annotation.annotationType_;
5992
- 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.");
6029
+ 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.");
5993
6030
  }
5994
6031
  }
5995
6032
 
6033
+ var ENTRY_0 = /*#__PURE__*/createArrayEntryDescriptor(0);
5996
6034
  /**
5997
6035
  * This array buffer contains two lists of properties, so that all arrays
5998
6036
  * can recycle their property definitions, which significantly improves performance of creating
5999
6037
  * properties on the fly.
6000
6038
  */
6001
6039
 
6040
+
6002
6041
  var OBSERVABLE_ARRAY_BUFFER_SIZE = 0; // Typescript workaround to make sure ObservableArray extends Array
6003
6042
 
6004
6043
  var StubArray = function StubArray() {};
@@ -6044,6 +6083,12 @@
6044
6083
  allowStateChangesEnd(prev);
6045
6084
  }
6046
6085
 
6086
+ {
6087
+ // Seems that Safari won't use numeric prototype setter untill any * numeric property is
6088
+ // defined on the instance. After that it works fine, even if this property is deleted.
6089
+ Object.defineProperty(_assertThisInitialized(_this), "0", ENTRY_0);
6090
+ }
6091
+
6047
6092
  return _this;
6048
6093
  }
6049
6094