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.
package/dist/mobx.esm.js CHANGED
@@ -166,12 +166,11 @@ function isObject(value) {
166
166
  return value !== null && typeof value === "object";
167
167
  }
168
168
  function isPlainObject(value) {
169
- var _proto$constructor;
170
-
171
169
  if (!isObject(value)) return false;
172
170
  var proto = Object.getPrototypeOf(value);
173
171
  if (proto == null) return true;
174
- return ((_proto$constructor = proto.constructor) == null ? void 0 : _proto$constructor.toString()) === plainObjectString;
172
+ var protoConstructor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
173
+ return typeof protoConstructor === "function" && protoConstructor.toString() === plainObjectString;
175
174
  } // https://stackoverflow.com/a/37865170
176
175
 
177
176
  function isGenerator(obj) {
@@ -266,6 +265,9 @@ function _defineProperties(target, props) {
266
265
  function _createClass(Constructor, protoProps, staticProps) {
267
266
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
268
267
  if (staticProps) _defineProperties(Constructor, staticProps);
268
+ Object.defineProperty(Constructor, "prototype", {
269
+ writable: false
270
+ });
269
271
  return Constructor;
270
272
  }
271
273
 
@@ -290,7 +292,17 @@ function _extends() {
290
292
  function _inheritsLoose(subClass, superClass) {
291
293
  subClass.prototype = Object.create(superClass.prototype);
292
294
  subClass.prototype.constructor = subClass;
293
- subClass.__proto__ = superClass;
295
+
296
+ _setPrototypeOf(subClass, superClass);
297
+ }
298
+
299
+ function _setPrototypeOf(o, p) {
300
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
301
+ o.__proto__ = p;
302
+ return o;
303
+ };
304
+
305
+ return _setPrototypeOf(o, p);
294
306
  }
295
307
 
296
308
  function _assertThisInitialized(self) {
@@ -319,28 +331,24 @@ function _arrayLikeToArray(arr, len) {
319
331
  }
320
332
 
321
333
  function _createForOfIteratorHelperLoose(o, allowArrayLike) {
322
- var it;
323
-
324
- if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
325
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
326
- if (it) o = it;
327
- var i = 0;
328
- return function () {
329
- if (i >= o.length) return {
330
- done: true
331
- };
332
- return {
333
- done: false,
334
- value: o[i++]
335
- };
334
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
335
+ if (it) return (it = it.call(o)).next.bind(it);
336
+
337
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
338
+ if (it) o = it;
339
+ var i = 0;
340
+ return function () {
341
+ if (i >= o.length) return {
342
+ done: true
336
343
  };
337
- }
338
-
339
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
344
+ return {
345
+ done: false,
346
+ value: o[i++]
347
+ };
348
+ };
340
349
  }
341
350
 
342
- it = o[Symbol.iterator]();
343
- return it.next.bind(it);
351
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
344
352
  }
345
353
 
346
354
  var storedAnnotationsSymbol = /*#__PURE__*/Symbol("mobx-stored-annotations");
@@ -624,7 +632,7 @@ function make_$1(adm, key, descriptor, source) {
624
632
  var _this$options_;
625
633
 
626
634
  // bound
627
- if ((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) {
635
+ if ((_this$options_ = this.options_) != null && _this$options_.bound) {
628
636
  return this.extend_(adm, key, descriptor, false) === null ? 0
629
637
  /* Cancel */
630
638
  : 1
@@ -682,7 +690,7 @@ safeDescriptors) {
682
690
  assertActionDescriptor(adm, annotation, key, descriptor);
683
691
  var value = descriptor.value;
684
692
 
685
- if ((_annotation$options_ = annotation.options_) == null ? void 0 : _annotation$options_.bound) {
693
+ if ((_annotation$options_ = annotation.options_) != null && _annotation$options_.bound) {
686
694
  var _adm$proxy_;
687
695
 
688
696
  value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
@@ -690,7 +698,7 @@ safeDescriptors) {
690
698
 
691
699
  return {
692
700
  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
693
- ((_annotation$options_4 = annotation.options_) == null ? void 0 : _annotation$options_4.bound) ? (_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_ : undefined),
701
+ (_annotation$options_4 = annotation.options_) != null && _annotation$options_4.bound ? (_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_ : undefined),
694
702
  // Non-configurable for classes
695
703
  // prevents accidental field redefinition in subclass
696
704
  configurable: safeDescriptors ? adm.isPlainObject_ : true,
@@ -725,7 +733,7 @@ function make_$2(adm, key, descriptor, source) {
725
733
  // bound - must annotate protos to support super.flow()
726
734
 
727
735
 
728
- if (((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) && !isFlow(adm.target_[key])) {
736
+ if ((_this$options_ = this.options_) != null && _this$options_.bound && !isFlow(adm.target_[key])) {
729
737
  if (this.extend_(adm, key, descriptor, false) === null) return 0
730
738
  /* Cancel */
731
739
  ;
@@ -908,11 +916,11 @@ function make_$5(adm, key, descriptor, source) {
908
916
  if (isGenerator(descriptor.value)) {
909
917
  var _this$options_;
910
918
 
911
- var flowAnnotation = ((_this$options_ = this.options_) == null ? void 0 : _this$options_.autoBind) ? flow.bound : flow;
919
+ var flowAnnotation = (_this$options_ = this.options_) != null && _this$options_.autoBind ? flow.bound : flow;
912
920
  return flowAnnotation.make_(adm, key, descriptor, source);
913
921
  }
914
922
 
915
- var actionAnnotation = ((_this$options_2 = this.options_) == null ? void 0 : _this$options_2.autoBind) ? autoAction.bound : autoAction;
923
+ var actionAnnotation = (_this$options_2 = this.options_) != null && _this$options_2.autoBind ? autoAction.bound : autoAction;
916
924
  return actionAnnotation.make_(adm, key, descriptor, source);
917
925
  } // other -> observable
918
926
  // Copy props from proto as well, see test:
@@ -921,7 +929,7 @@ function make_$5(adm, key, descriptor, source) {
921
929
 
922
930
  var observableAnnotation = ((_this$options_3 = this.options_) == null ? void 0 : _this$options_3.deep) === false ? observable.ref : observable; // if function respect autoBind option
923
931
 
924
- if (typeof descriptor.value === "function" && ((_this$options_4 = this.options_) == null ? void 0 : _this$options_4.autoBind)) {
932
+ if (typeof descriptor.value === "function" && (_this$options_4 = this.options_) != null && _this$options_4.autoBind) {
925
933
  var _adm$proxy_;
926
934
 
927
935
  descriptor.value = descriptor.value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
@@ -949,7 +957,7 @@ function extend_$5(adm, key, descriptor, proxyTrap) {
949
957
  // if function respect autoBind option
950
958
 
951
959
 
952
- if (typeof descriptor.value === "function" && ((_this$options_5 = this.options_) == null ? void 0 : _this$options_5.autoBind)) {
960
+ if (typeof descriptor.value === "function" && (_this$options_5 = this.options_) != null && _this$options_5.autoBind) {
953
961
  var _adm$proxy_2;
954
962
 
955
963
  descriptor.value = descriptor.value.bind((_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_);
@@ -1227,7 +1235,7 @@ function allowStateChangesEnd(prev) {
1227
1235
  var _Symbol$toPrimitive;
1228
1236
  var CREATE = "create";
1229
1237
  _Symbol$toPrimitive = Symbol.toPrimitive;
1230
- var ObservableValue = /*#__PURE__*/function (_Atom) {
1238
+ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
1231
1239
  _inheritsLoose(ObservableValue, _Atom);
1232
1240
 
1233
1241
  function ObservableValue(value, enhancer, name_, notifySpy, equals) {
@@ -1374,12 +1382,12 @@ var ObservableValue = /*#__PURE__*/function (_Atom) {
1374
1382
  return toPrimitive(this.get());
1375
1383
  };
1376
1384
 
1377
- _proto[_Symbol$toPrimitive] = function () {
1385
+ _proto[_Symbol$toPrimitive2] = function () {
1378
1386
  return this.valueOf();
1379
1387
  };
1380
1388
 
1381
1389
  return ObservableValue;
1382
- }(Atom);
1390
+ }(Atom, _Symbol$toPrimitive);
1383
1391
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1384
1392
 
1385
1393
  var _Symbol$toPrimitive$1;
@@ -1404,7 +1412,7 @@ var _Symbol$toPrimitive$1;
1404
1412
  */
1405
1413
 
1406
1414
  _Symbol$toPrimitive$1 = Symbol.toPrimitive;
1407
- var ComputedValue = /*#__PURE__*/function () {
1415
+ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
1408
1416
  // nodes we are looking at. Our value depends on these nodes
1409
1417
  // during tracking it's an array with new observed observers
1410
1418
  // to check for cycles
@@ -1458,7 +1466,7 @@ var ComputedValue = /*#__PURE__*/function () {
1458
1466
 
1459
1467
  this.equals_ = options.equals || (options.compareStructural || options.struct ? comparer.structural : comparer["default"]);
1460
1468
  this.scope_ = options.context;
1461
- this.requiresReaction_ = !!options.requiresReaction;
1469
+ this.requiresReaction_ = options.requiresReaction;
1462
1470
  this.keepAlive_ = !!options.keepAlive;
1463
1471
  }
1464
1472
 
@@ -1627,7 +1635,7 @@ var ComputedValue = /*#__PURE__*/function () {
1627
1635
  console.log("[mobx.trace] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
1628
1636
  }
1629
1637
 
1630
- if (globalState.computedRequiresReaction || this.requiresReaction_) {
1638
+ if (typeof this.requiresReaction_ === "boolean" ? this.requiresReaction_ : globalState.computedRequiresReaction) {
1631
1639
  console.warn("[mobx] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
1632
1640
  }
1633
1641
  };
@@ -1640,12 +1648,12 @@ var ComputedValue = /*#__PURE__*/function () {
1640
1648
  return toPrimitive(this.get());
1641
1649
  };
1642
1650
 
1643
- _proto[_Symbol$toPrimitive$1] = function () {
1651
+ _proto[_Symbol$toPrimitive2] = function () {
1644
1652
  return this.valueOf();
1645
1653
  };
1646
1654
 
1647
1655
  return ComputedValue;
1648
- }();
1656
+ }(_Symbol$toPrimitive$1);
1649
1657
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1650
1658
 
1651
1659
  var IDerivationState_;
@@ -2190,8 +2198,8 @@ function propagateChangeConfirmed(observable) {
2190
2198
  }
2191
2199
  } else if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_ // this happens during computing of `d`, just keep lowestObserverState up to date.
2192
2200
  ) {
2193
- observable.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
2194
- }
2201
+ observable.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
2202
+ }
2195
2203
  }); // invariantLOS(observable, "confirmed end");
2196
2204
  } // Used by computed when its dependency changed, but we don't wan't to immediately recompute.
2197
2205
 
@@ -3335,7 +3343,7 @@ function whenPromise(predicate, opts) {
3335
3343
 
3336
3344
  cancel = function cancel() {
3337
3345
  disposer();
3338
- reject("WHEN_CANCELLED");
3346
+ reject(new Error("WHEN_CANCELLED"));
3339
3347
  };
3340
3348
  });
3341
3349
  res.cancel = cancel;
@@ -3466,7 +3474,11 @@ function makeObservable(target, annotations, options) {
3466
3474
  try {
3467
3475
  var _annotations;
3468
3476
 
3469
- // Default to decorators
3477
+ if (process.env.NODE_ENV !== "production" && annotations && target[storedAnnotationsSymbol]) {
3478
+ die("makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.");
3479
+ } // Default to decorators
3480
+
3481
+
3470
3482
  (_annotations = annotations) != null ? _annotations : annotations = collectStoredAnnotations(target); // Annotate
3471
3483
 
3472
3484
  ownKeys(annotations).forEach(function (key) {
@@ -3689,9 +3701,12 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
3689
3701
 
3690
3702
  return (_this$values_ = this.values_).splice.apply(_this$values_, [index, deleteCount].concat(newItems));
3691
3703
  } else {
3692
- var res = this.values_.slice(index, index + deleteCount);
3693
- var oldItems = this.values_.slice(index + deleteCount);
3694
- this.values_.length = index + newItems.length - deleteCount;
3704
+ // The items removed by the splice
3705
+ var res = this.values_.slice(index, index + deleteCount); // The items that that should remain at the end of the array
3706
+
3707
+ var oldItems = this.values_.slice(index + deleteCount); // New length is the previous length + addition count - deletion count
3708
+
3709
+ this.values_.length += newItems.length - deleteCount;
3695
3710
 
3696
3711
  for (var i = 0; i < newItems.length; i++) {
3697
3712
  this.values_[index + i] = newItems[i];
@@ -4008,7 +4023,7 @@ var DELETE = "delete"; // just extend Map? See also https://gist.github.com/nest
4008
4023
 
4009
4024
  _Symbol$iterator = Symbol.iterator;
4010
4025
  _Symbol$toStringTag = Symbol.toStringTag;
4011
- var ObservableMap = /*#__PURE__*/function () {
4026
+ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4012
4027
  // hasMap, not hashMap >-).
4013
4028
  function ObservableMap(initialData, enhancer_, name_) {
4014
4029
  if (enhancer_ === void 0) {
@@ -4114,7 +4129,8 @@ var ObservableMap = /*#__PURE__*/function () {
4114
4129
  name: key
4115
4130
  } : null;
4116
4131
 
4117
- if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(_change);
4132
+ if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(_change); // TODO fix type
4133
+
4118
4134
  transaction(function () {
4119
4135
  var _this2$hasMap_$get;
4120
4136
 
@@ -4152,7 +4168,8 @@ var ObservableMap = /*#__PURE__*/function () {
4152
4168
  name: key,
4153
4169
  newValue: newValue
4154
4170
  } : null;
4155
- if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(change);
4171
+ if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(change); // TODO fix type
4172
+
4156
4173
  observable.setNewValue_(newValue);
4157
4174
  if (notify) notifyListeners(this, change);
4158
4175
  if (process.env.NODE_ENV !== "production" && notifySpy) spyReportEnd();
@@ -4186,7 +4203,8 @@ var ObservableMap = /*#__PURE__*/function () {
4186
4203
  name: key,
4187
4204
  newValue: newValue
4188
4205
  } : null;
4189
- if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(change);
4206
+ if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(change); // TODO fix type
4207
+
4190
4208
  if (notify) notifyListeners(this, change);
4191
4209
  if (process.env.NODE_ENV !== "production" && notifySpy) spyReportEnd();
4192
4210
  };
@@ -4243,7 +4261,7 @@ var ObservableMap = /*#__PURE__*/function () {
4243
4261
  });
4244
4262
  };
4245
4263
 
4246
- _proto[_Symbol$iterator] = function () {
4264
+ _proto[_Symbol$iterator2] = function () {
4247
4265
  return this.entries();
4248
4266
  };
4249
4267
 
@@ -4423,14 +4441,14 @@ var ObservableMap = /*#__PURE__*/function () {
4423
4441
  return this.data_.size;
4424
4442
  }
4425
4443
  }, {
4426
- key: _Symbol$toStringTag,
4444
+ key: _Symbol$toStringTag2,
4427
4445
  get: function get() {
4428
4446
  return "Map";
4429
4447
  }
4430
4448
  }]);
4431
4449
 
4432
4450
  return ObservableMap;
4433
- }(); // eslint-disable-next-line
4451
+ }(_Symbol$iterator, _Symbol$toStringTag); // eslint-disable-next-line
4434
4452
 
4435
4453
  var isObservableMap = /*#__PURE__*/createInstanceofPredicate("ObservableMap", ObservableMap);
4436
4454
 
@@ -4456,7 +4474,7 @@ var _Symbol$iterator$1, _Symbol$toStringTag$1;
4456
4474
  var ObservableSetMarker = {};
4457
4475
  _Symbol$iterator$1 = Symbol.iterator;
4458
4476
  _Symbol$toStringTag$1 = Symbol.toStringTag;
4459
- var ObservableSet = /*#__PURE__*/function () {
4477
+ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4460
4478
  function ObservableSet(initialData, enhancer, name_) {
4461
4479
  if (enhancer === void 0) {
4462
4480
  enhancer = deepEnhancer;
@@ -4689,7 +4707,7 @@ var ObservableSet = /*#__PURE__*/function () {
4689
4707
  return "[object ObservableSet]";
4690
4708
  };
4691
4709
 
4692
- _proto[_Symbol$iterator$1] = function () {
4710
+ _proto[_Symbol$iterator2] = function () {
4693
4711
  return this.values();
4694
4712
  };
4695
4713
 
@@ -4700,14 +4718,14 @@ var ObservableSet = /*#__PURE__*/function () {
4700
4718
  return this.data_.size;
4701
4719
  }
4702
4720
  }, {
4703
- key: _Symbol$toStringTag$1,
4721
+ key: _Symbol$toStringTag2,
4704
4722
  get: function get() {
4705
4723
  return "Set";
4706
4724
  }
4707
4725
  }]);
4708
4726
 
4709
4727
  return ObservableSet;
4710
- }(); // eslint-disable-next-line
4728
+ }(_Symbol$iterator$1, _Symbol$toStringTag$1); // eslint-disable-next-line
4711
4729
 
4712
4730
  var isObservableSet = /*#__PURE__*/createInstanceofPredicate("ObservableSet", ObservableSet);
4713
4731
 
@@ -4893,7 +4911,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4893
4911
  // When called from super() some props may not exist yet.
4894
4912
  // However we don't have to worry about missing prop,
4895
4913
  // because the decorator must have been applied to something.
4896
- if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) == null ? void 0 : _this$target_$storedA[key]) {
4914
+ if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) != null && _this$target_$storedA[key]) {
4897
4915
  return; // will be annotated by subclass constructor
4898
4916
  } else {
4899
4917
  die(1, annotation.annotationType_, this.name_ + "." + key.toString());
@@ -5397,7 +5415,7 @@ inherit(StubArray, Array.prototype); // Weex proto freeze protection was here,
5397
5415
  // but it is unclear why the hack is need as MobX never changed the prototype
5398
5416
  // anyway, so removed it in V6
5399
5417
 
5400
- var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5418
+ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringTag, _Symbol$iterator) {
5401
5419
  _inheritsLoose(LegacyObservableArray, _StubArray);
5402
5420
 
5403
5421
  function LegacyObservableArray(initialValues, enhancer, name, owned) {
@@ -5442,7 +5460,7 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5442
5460
  }));
5443
5461
  };
5444
5462
 
5445
- _proto[Symbol.iterator] = function () {
5463
+ _proto[_Symbol$iterator] = function () {
5446
5464
  var self = this;
5447
5465
  var nextIndex = 0;
5448
5466
  return makeIterable({
@@ -5468,14 +5486,14 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5468
5486
  this[$mobx].setArrayLength_(newLength);
5469
5487
  }
5470
5488
  }, {
5471
- key: Symbol.toStringTag,
5489
+ key: _Symbol$toStringTag,
5472
5490
  get: function get() {
5473
5491
  return "Array";
5474
5492
  }
5475
5493
  }]);
5476
5494
 
5477
5495
  return LegacyObservableArray;
5478
- }(StubArray);
5496
+ }(StubArray, Symbol.toStringTag, Symbol.iterator);
5479
5497
 
5480
5498
  Object.entries(arrayExtensions).forEach(function (_ref) {
5481
5499
  var prop = _ref[0],