mobx 6.3.5 → 6.3.9

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.
@@ -164,12 +164,11 @@ function isObject(value) {
164
164
  return value !== null && typeof value === "object";
165
165
  }
166
166
  function isPlainObject(value) {
167
- var _proto$constructor;
168
-
169
167
  if (!isObject(value)) return false;
170
168
  var proto = Object.getPrototypeOf(value);
171
169
  if (proto == null) return true;
172
- return ((_proto$constructor = proto.constructor) == null ? void 0 : _proto$constructor.toString()) === plainObjectString;
170
+ var protoConstructor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
171
+ return typeof protoConstructor === "function" && protoConstructor.toString() === plainObjectString;
173
172
  } // https://stackoverflow.com/a/37865170
174
173
 
175
174
  function isGenerator(obj) {
@@ -264,6 +263,9 @@ function _defineProperties(target, props) {
264
263
  function _createClass(Constructor, protoProps, staticProps) {
265
264
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
266
265
  if (staticProps) _defineProperties(Constructor, staticProps);
266
+ Object.defineProperty(Constructor, "prototype", {
267
+ writable: false
268
+ });
267
269
  return Constructor;
268
270
  }
269
271
 
@@ -288,7 +290,17 @@ function _extends() {
288
290
  function _inheritsLoose(subClass, superClass) {
289
291
  subClass.prototype = Object.create(superClass.prototype);
290
292
  subClass.prototype.constructor = subClass;
291
- subClass.__proto__ = superClass;
293
+
294
+ _setPrototypeOf(subClass, superClass);
295
+ }
296
+
297
+ function _setPrototypeOf(o, p) {
298
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
299
+ o.__proto__ = p;
300
+ return o;
301
+ };
302
+
303
+ return _setPrototypeOf(o, p);
292
304
  }
293
305
 
294
306
  function _assertThisInitialized(self) {
@@ -317,28 +329,24 @@ function _arrayLikeToArray(arr, len) {
317
329
  }
318
330
 
319
331
  function _createForOfIteratorHelperLoose(o, allowArrayLike) {
320
- var it;
321
-
322
- if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
323
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
324
- if (it) o = it;
325
- var i = 0;
326
- return function () {
327
- if (i >= o.length) return {
328
- done: true
329
- };
330
- return {
331
- done: false,
332
- value: o[i++]
333
- };
332
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
333
+ if (it) return (it = it.call(o)).next.bind(it);
334
+
335
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
336
+ if (it) o = it;
337
+ var i = 0;
338
+ return function () {
339
+ if (i >= o.length) return {
340
+ done: true
334
341
  };
335
- }
336
-
337
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
342
+ return {
343
+ done: false,
344
+ value: o[i++]
345
+ };
346
+ };
338
347
  }
339
348
 
340
- it = o[Symbol.iterator]();
341
- return it.next.bind(it);
349
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
342
350
  }
343
351
 
344
352
  var storedAnnotationsSymbol = /*#__PURE__*/Symbol("mobx-stored-annotations");
@@ -622,7 +630,7 @@ function make_$1(adm, key, descriptor, source) {
622
630
  var _this$options_;
623
631
 
624
632
  // bound
625
- if ((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) {
633
+ if ((_this$options_ = this.options_) != null && _this$options_.bound) {
626
634
  return this.extend_(adm, key, descriptor, false) === null ? 0
627
635
  /* Cancel */
628
636
  : 1
@@ -680,7 +688,7 @@ safeDescriptors) {
680
688
  assertActionDescriptor(adm, annotation, key, descriptor);
681
689
  var value = descriptor.value;
682
690
 
683
- if ((_annotation$options_ = annotation.options_) == null ? void 0 : _annotation$options_.bound) {
691
+ if ((_annotation$options_ = annotation.options_) != null && _annotation$options_.bound) {
684
692
  var _adm$proxy_;
685
693
 
686
694
  value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
@@ -688,7 +696,7 @@ safeDescriptors) {
688
696
 
689
697
  return {
690
698
  value: createAction((_annotation$options_$ = (_annotation$options_2 = annotation.options_) == null ? void 0 : _annotation$options_2.name) != null ? _annotation$options_$ : key.toString(), value, (_annotation$options_$2 = (_annotation$options_3 = annotation.options_) == null ? void 0 : _annotation$options_3.autoAction) != null ? _annotation$options_$2 : false, // https://github.com/mobxjs/mobx/discussions/3140
691
- ((_annotation$options_4 = annotation.options_) == null ? void 0 : _annotation$options_4.bound) ? (_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_ : undefined),
699
+ (_annotation$options_4 = annotation.options_) != null && _annotation$options_4.bound ? (_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_ : undefined),
692
700
  // Non-configurable for classes
693
701
  // prevents accidental field redefinition in subclass
694
702
  configurable: safeDescriptors ? adm.isPlainObject_ : true,
@@ -723,7 +731,7 @@ function make_$2(adm, key, descriptor, source) {
723
731
  // bound - must annotate protos to support super.flow()
724
732
 
725
733
 
726
- if (((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) && !isFlow(adm.target_[key])) {
734
+ if ((_this$options_ = this.options_) != null && _this$options_.bound && !isFlow(adm.target_[key])) {
727
735
  if (this.extend_(adm, key, descriptor, false) === null) return 0
728
736
  /* Cancel */
729
737
  ;
@@ -906,11 +914,11 @@ function make_$5(adm, key, descriptor, source) {
906
914
  if (isGenerator(descriptor.value)) {
907
915
  var _this$options_;
908
916
 
909
- var flowAnnotation = ((_this$options_ = this.options_) == null ? void 0 : _this$options_.autoBind) ? flow.bound : flow;
917
+ var flowAnnotation = (_this$options_ = this.options_) != null && _this$options_.autoBind ? flow.bound : flow;
910
918
  return flowAnnotation.make_(adm, key, descriptor, source);
911
919
  }
912
920
 
913
- var actionAnnotation = ((_this$options_2 = this.options_) == null ? void 0 : _this$options_2.autoBind) ? autoAction.bound : autoAction;
921
+ var actionAnnotation = (_this$options_2 = this.options_) != null && _this$options_2.autoBind ? autoAction.bound : autoAction;
914
922
  return actionAnnotation.make_(adm, key, descriptor, source);
915
923
  } // other -> observable
916
924
  // Copy props from proto as well, see test:
@@ -919,7 +927,7 @@ function make_$5(adm, key, descriptor, source) {
919
927
 
920
928
  var observableAnnotation = ((_this$options_3 = this.options_) == null ? void 0 : _this$options_3.deep) === false ? observable.ref : observable; // if function respect autoBind option
921
929
 
922
- if (typeof descriptor.value === "function" && ((_this$options_4 = this.options_) == null ? void 0 : _this$options_4.autoBind)) {
930
+ if (typeof descriptor.value === "function" && (_this$options_4 = this.options_) != null && _this$options_4.autoBind) {
923
931
  var _adm$proxy_;
924
932
 
925
933
  descriptor.value = descriptor.value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
@@ -947,7 +955,7 @@ function extend_$5(adm, key, descriptor, proxyTrap) {
947
955
  // if function respect autoBind option
948
956
 
949
957
 
950
- if (typeof descriptor.value === "function" && ((_this$options_5 = this.options_) == null ? void 0 : _this$options_5.autoBind)) {
958
+ if (typeof descriptor.value === "function" && (_this$options_5 = this.options_) != null && _this$options_5.autoBind) {
951
959
  var _adm$proxy_2;
952
960
 
953
961
  descriptor.value = descriptor.value.bind((_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_);
@@ -1225,7 +1233,7 @@ function allowStateChangesEnd(prev) {
1225
1233
  var _Symbol$toPrimitive;
1226
1234
  var CREATE = "create";
1227
1235
  _Symbol$toPrimitive = Symbol.toPrimitive;
1228
- var ObservableValue = /*#__PURE__*/function (_Atom) {
1236
+ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
1229
1237
  _inheritsLoose(ObservableValue, _Atom);
1230
1238
 
1231
1239
  function ObservableValue(value, enhancer, name_, notifySpy, equals) {
@@ -1372,12 +1380,12 @@ var ObservableValue = /*#__PURE__*/function (_Atom) {
1372
1380
  return toPrimitive(this.get());
1373
1381
  };
1374
1382
 
1375
- _proto[_Symbol$toPrimitive] = function () {
1383
+ _proto[_Symbol$toPrimitive2] = function () {
1376
1384
  return this.valueOf();
1377
1385
  };
1378
1386
 
1379
1387
  return ObservableValue;
1380
- }(Atom);
1388
+ }(Atom, _Symbol$toPrimitive);
1381
1389
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1382
1390
 
1383
1391
  var _Symbol$toPrimitive$1;
@@ -1402,7 +1410,7 @@ var _Symbol$toPrimitive$1;
1402
1410
  */
1403
1411
 
1404
1412
  _Symbol$toPrimitive$1 = Symbol.toPrimitive;
1405
- var ComputedValue = /*#__PURE__*/function () {
1413
+ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
1406
1414
  // nodes we are looking at. Our value depends on these nodes
1407
1415
  // during tracking it's an array with new observed observers
1408
1416
  // to check for cycles
@@ -1456,7 +1464,7 @@ var ComputedValue = /*#__PURE__*/function () {
1456
1464
 
1457
1465
  this.equals_ = options.equals || (options.compareStructural || options.struct ? comparer.structural : comparer["default"]);
1458
1466
  this.scope_ = options.context;
1459
- this.requiresReaction_ = !!options.requiresReaction;
1467
+ this.requiresReaction_ = options.requiresReaction;
1460
1468
  this.keepAlive_ = !!options.keepAlive;
1461
1469
  }
1462
1470
 
@@ -1624,7 +1632,7 @@ var ComputedValue = /*#__PURE__*/function () {
1624
1632
  console.log("[mobx.trace] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
1625
1633
  }
1626
1634
 
1627
- if (globalState.computedRequiresReaction || this.requiresReaction_) {
1635
+ if (typeof this.requiresReaction_ === "boolean" ? this.requiresReaction_ : globalState.computedRequiresReaction) {
1628
1636
  console.warn("[mobx] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
1629
1637
  }
1630
1638
  };
@@ -1637,12 +1645,12 @@ var ComputedValue = /*#__PURE__*/function () {
1637
1645
  return toPrimitive(this.get());
1638
1646
  };
1639
1647
 
1640
- _proto[_Symbol$toPrimitive$1] = function () {
1648
+ _proto[_Symbol$toPrimitive2] = function () {
1641
1649
  return this.valueOf();
1642
1650
  };
1643
1651
 
1644
1652
  return ComputedValue;
1645
- }();
1653
+ }(_Symbol$toPrimitive$1);
1646
1654
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1647
1655
 
1648
1656
  var IDerivationState_;
@@ -2183,8 +2191,8 @@ function propagateChangeConfirmed(observable) {
2183
2191
  }
2184
2192
  } else if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_ // this happens during computing of `d`, just keep lowestObserverState up to date.
2185
2193
  ) {
2186
- observable.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
2187
- }
2194
+ observable.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
2195
+ }
2188
2196
  }); // invariantLOS(observable, "confirmed end");
2189
2197
  } // Used by computed when its dependency changed, but we don't wan't to immediately recompute.
2190
2198
 
@@ -3321,7 +3329,7 @@ function whenPromise(predicate, opts) {
3321
3329
 
3322
3330
  cancel = function cancel() {
3323
3331
  disposer();
3324
- reject("WHEN_CANCELLED");
3332
+ reject(new Error("WHEN_CANCELLED"));
3325
3333
  };
3326
3334
  });
3327
3335
  res.cancel = cancel;
@@ -3452,7 +3460,11 @@ function makeObservable(target, annotations, options) {
3452
3460
  try {
3453
3461
  var _annotations;
3454
3462
 
3455
- // Default to decorators
3463
+ if ("development" !== "production" && annotations && target[storedAnnotationsSymbol]) {
3464
+ die("makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.");
3465
+ } // Default to decorators
3466
+
3467
+
3456
3468
  (_annotations = annotations) != null ? _annotations : annotations = collectStoredAnnotations(target); // Annotate
3457
3469
 
3458
3470
  ownKeys(annotations).forEach(function (key) {
@@ -3675,9 +3687,12 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
3675
3687
 
3676
3688
  return (_this$values_ = this.values_).splice.apply(_this$values_, [index, deleteCount].concat(newItems));
3677
3689
  } else {
3678
- var res = this.values_.slice(index, index + deleteCount);
3679
- var oldItems = this.values_.slice(index + deleteCount);
3680
- this.values_.length = index + newItems.length - deleteCount;
3690
+ // The items removed by the splice
3691
+ var res = this.values_.slice(index, index + deleteCount); // The items that that should remain at the end of the array
3692
+
3693
+ var oldItems = this.values_.slice(index + deleteCount); // New length is the previous length + addition count - deletion count
3694
+
3695
+ this.values_.length += newItems.length - deleteCount;
3681
3696
 
3682
3697
  for (var i = 0; i < newItems.length; i++) {
3683
3698
  this.values_[index + i] = newItems[i];
@@ -3994,7 +4009,7 @@ var DELETE = "delete"; // just extend Map? See also https://gist.github.com/nest
3994
4009
 
3995
4010
  _Symbol$iterator = Symbol.iterator;
3996
4011
  _Symbol$toStringTag = Symbol.toStringTag;
3997
- var ObservableMap = /*#__PURE__*/function () {
4012
+ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
3998
4013
  // hasMap, not hashMap >-).
3999
4014
  function ObservableMap(initialData, enhancer_, name_) {
4000
4015
  if (enhancer_ === void 0) {
@@ -4100,7 +4115,8 @@ var ObservableMap = /*#__PURE__*/function () {
4100
4115
  name: key
4101
4116
  } : null;
4102
4117
 
4103
- if ( notifySpy) spyReportStart(_change);
4118
+ if ( notifySpy) spyReportStart(_change); // TODO fix type
4119
+
4104
4120
  transaction(function () {
4105
4121
  var _this2$hasMap_$get;
4106
4122
 
@@ -4138,7 +4154,8 @@ var ObservableMap = /*#__PURE__*/function () {
4138
4154
  name: key,
4139
4155
  newValue: newValue
4140
4156
  } : null;
4141
- if ( notifySpy) spyReportStart(change);
4157
+ if ( notifySpy) spyReportStart(change); // TODO fix type
4158
+
4142
4159
  observable.setNewValue_(newValue);
4143
4160
  if (notify) notifyListeners(this, change);
4144
4161
  if ( notifySpy) spyReportEnd();
@@ -4172,7 +4189,8 @@ var ObservableMap = /*#__PURE__*/function () {
4172
4189
  name: key,
4173
4190
  newValue: newValue
4174
4191
  } : null;
4175
- if ( notifySpy) spyReportStart(change);
4192
+ if ( notifySpy) spyReportStart(change); // TODO fix type
4193
+
4176
4194
  if (notify) notifyListeners(this, change);
4177
4195
  if ( notifySpy) spyReportEnd();
4178
4196
  };
@@ -4229,7 +4247,7 @@ var ObservableMap = /*#__PURE__*/function () {
4229
4247
  });
4230
4248
  };
4231
4249
 
4232
- _proto[_Symbol$iterator] = function () {
4250
+ _proto[_Symbol$iterator2] = function () {
4233
4251
  return this.entries();
4234
4252
  };
4235
4253
 
@@ -4409,14 +4427,14 @@ var ObservableMap = /*#__PURE__*/function () {
4409
4427
  return this.data_.size;
4410
4428
  }
4411
4429
  }, {
4412
- key: _Symbol$toStringTag,
4430
+ key: _Symbol$toStringTag2,
4413
4431
  get: function get() {
4414
4432
  return "Map";
4415
4433
  }
4416
4434
  }]);
4417
4435
 
4418
4436
  return ObservableMap;
4419
- }(); // eslint-disable-next-line
4437
+ }(_Symbol$iterator, _Symbol$toStringTag); // eslint-disable-next-line
4420
4438
 
4421
4439
  var isObservableMap = /*#__PURE__*/createInstanceofPredicate("ObservableMap", ObservableMap);
4422
4440
 
@@ -4442,7 +4460,7 @@ var _Symbol$iterator$1, _Symbol$toStringTag$1;
4442
4460
  var ObservableSetMarker = {};
4443
4461
  _Symbol$iterator$1 = Symbol.iterator;
4444
4462
  _Symbol$toStringTag$1 = Symbol.toStringTag;
4445
- var ObservableSet = /*#__PURE__*/function () {
4463
+ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4446
4464
  function ObservableSet(initialData, enhancer, name_) {
4447
4465
  if (enhancer === void 0) {
4448
4466
  enhancer = deepEnhancer;
@@ -4675,7 +4693,7 @@ var ObservableSet = /*#__PURE__*/function () {
4675
4693
  return "[object ObservableSet]";
4676
4694
  };
4677
4695
 
4678
- _proto[_Symbol$iterator$1] = function () {
4696
+ _proto[_Symbol$iterator2] = function () {
4679
4697
  return this.values();
4680
4698
  };
4681
4699
 
@@ -4686,14 +4704,14 @@ var ObservableSet = /*#__PURE__*/function () {
4686
4704
  return this.data_.size;
4687
4705
  }
4688
4706
  }, {
4689
- key: _Symbol$toStringTag$1,
4707
+ key: _Symbol$toStringTag2,
4690
4708
  get: function get() {
4691
4709
  return "Set";
4692
4710
  }
4693
4711
  }]);
4694
4712
 
4695
4713
  return ObservableSet;
4696
- }(); // eslint-disable-next-line
4714
+ }(_Symbol$iterator$1, _Symbol$toStringTag$1); // eslint-disable-next-line
4697
4715
 
4698
4716
  var isObservableSet = /*#__PURE__*/createInstanceofPredicate("ObservableSet", ObservableSet);
4699
4717
 
@@ -4879,7 +4897,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4879
4897
  // When called from super() some props may not exist yet.
4880
4898
  // However we don't have to worry about missing prop,
4881
4899
  // because the decorator must have been applied to something.
4882
- if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) == null ? void 0 : _this$target_$storedA[key]) {
4900
+ if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) != null && _this$target_$storedA[key]) {
4883
4901
  return; // will be annotated by subclass constructor
4884
4902
  } else {
4885
4903
  die(1, annotation.annotationType_, this.name_ + "." + key.toString());
@@ -5383,7 +5401,7 @@ inherit(StubArray, Array.prototype); // Weex proto freeze protection was here,
5383
5401
  // but it is unclear why the hack is need as MobX never changed the prototype
5384
5402
  // anyway, so removed it in V6
5385
5403
 
5386
- var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5404
+ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringTag, _Symbol$iterator) {
5387
5405
  _inheritsLoose(LegacyObservableArray, _StubArray);
5388
5406
 
5389
5407
  function LegacyObservableArray(initialValues, enhancer, name, owned) {
@@ -5428,7 +5446,7 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5428
5446
  }));
5429
5447
  };
5430
5448
 
5431
- _proto[Symbol.iterator] = function () {
5449
+ _proto[_Symbol$iterator] = function () {
5432
5450
  var self = this;
5433
5451
  var nextIndex = 0;
5434
5452
  return makeIterable({
@@ -5454,14 +5472,14 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5454
5472
  this[$mobx].setArrayLength_(newLength);
5455
5473
  }
5456
5474
  }, {
5457
- key: Symbol.toStringTag,
5475
+ key: _Symbol$toStringTag,
5458
5476
  get: function get() {
5459
5477
  return "Array";
5460
5478
  }
5461
5479
  }]);
5462
5480
 
5463
5481
  return LegacyObservableArray;
5464
- }(StubArray);
5482
+ }(StubArray, Symbol.toStringTag, Symbol.iterator);
5465
5483
 
5466
5484
  Object.entries(arrayExtensions).forEach(function (_ref) {
5467
5485
  var prop = _ref[0],