mobx 6.3.6 → 6.3.10

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
 
@@ -3693,9 +3701,12 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
3693
3701
 
3694
3702
  return (_this$values_ = this.values_).splice.apply(_this$values_, [index, deleteCount].concat(newItems));
3695
3703
  } else {
3696
- var res = this.values_.slice(index, index + deleteCount);
3697
- var oldItems = this.values_.slice(index + deleteCount);
3698
- 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;
3699
3710
 
3700
3711
  for (var i = 0; i < newItems.length; i++) {
3701
3712
  this.values_[index + i] = newItems[i];
@@ -4012,7 +4023,7 @@ var DELETE = "delete"; // just extend Map? See also https://gist.github.com/nest
4012
4023
 
4013
4024
  _Symbol$iterator = Symbol.iterator;
4014
4025
  _Symbol$toStringTag = Symbol.toStringTag;
4015
- var ObservableMap = /*#__PURE__*/function () {
4026
+ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4016
4027
  // hasMap, not hashMap >-).
4017
4028
  function ObservableMap(initialData, enhancer_, name_) {
4018
4029
  if (enhancer_ === void 0) {
@@ -4118,7 +4129,8 @@ var ObservableMap = /*#__PURE__*/function () {
4118
4129
  name: key
4119
4130
  } : null;
4120
4131
 
4121
- if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(_change);
4132
+ if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(_change); // TODO fix type
4133
+
4122
4134
  transaction(function () {
4123
4135
  var _this2$hasMap_$get;
4124
4136
 
@@ -4156,7 +4168,8 @@ var ObservableMap = /*#__PURE__*/function () {
4156
4168
  name: key,
4157
4169
  newValue: newValue
4158
4170
  } : null;
4159
- if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(change);
4171
+ if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(change); // TODO fix type
4172
+
4160
4173
  observable.setNewValue_(newValue);
4161
4174
  if (notify) notifyListeners(this, change);
4162
4175
  if (process.env.NODE_ENV !== "production" && notifySpy) spyReportEnd();
@@ -4190,7 +4203,8 @@ var ObservableMap = /*#__PURE__*/function () {
4190
4203
  name: key,
4191
4204
  newValue: newValue
4192
4205
  } : null;
4193
- if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(change);
4206
+ if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(change); // TODO fix type
4207
+
4194
4208
  if (notify) notifyListeners(this, change);
4195
4209
  if (process.env.NODE_ENV !== "production" && notifySpy) spyReportEnd();
4196
4210
  };
@@ -4247,7 +4261,7 @@ var ObservableMap = /*#__PURE__*/function () {
4247
4261
  });
4248
4262
  };
4249
4263
 
4250
- _proto[_Symbol$iterator] = function () {
4264
+ _proto[_Symbol$iterator2] = function () {
4251
4265
  return this.entries();
4252
4266
  };
4253
4267
 
@@ -4427,14 +4441,14 @@ var ObservableMap = /*#__PURE__*/function () {
4427
4441
  return this.data_.size;
4428
4442
  }
4429
4443
  }, {
4430
- key: _Symbol$toStringTag,
4444
+ key: _Symbol$toStringTag2,
4431
4445
  get: function get() {
4432
4446
  return "Map";
4433
4447
  }
4434
4448
  }]);
4435
4449
 
4436
4450
  return ObservableMap;
4437
- }(); // eslint-disable-next-line
4451
+ }(_Symbol$iterator, _Symbol$toStringTag); // eslint-disable-next-line
4438
4452
 
4439
4453
  var isObservableMap = /*#__PURE__*/createInstanceofPredicate("ObservableMap", ObservableMap);
4440
4454
 
@@ -4460,7 +4474,7 @@ var _Symbol$iterator$1, _Symbol$toStringTag$1;
4460
4474
  var ObservableSetMarker = {};
4461
4475
  _Symbol$iterator$1 = Symbol.iterator;
4462
4476
  _Symbol$toStringTag$1 = Symbol.toStringTag;
4463
- var ObservableSet = /*#__PURE__*/function () {
4477
+ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4464
4478
  function ObservableSet(initialData, enhancer, name_) {
4465
4479
  if (enhancer === void 0) {
4466
4480
  enhancer = deepEnhancer;
@@ -4693,7 +4707,7 @@ var ObservableSet = /*#__PURE__*/function () {
4693
4707
  return "[object ObservableSet]";
4694
4708
  };
4695
4709
 
4696
- _proto[_Symbol$iterator$1] = function () {
4710
+ _proto[_Symbol$iterator2] = function () {
4697
4711
  return this.values();
4698
4712
  };
4699
4713
 
@@ -4704,14 +4718,14 @@ var ObservableSet = /*#__PURE__*/function () {
4704
4718
  return this.data_.size;
4705
4719
  }
4706
4720
  }, {
4707
- key: _Symbol$toStringTag$1,
4721
+ key: _Symbol$toStringTag2,
4708
4722
  get: function get() {
4709
4723
  return "Set";
4710
4724
  }
4711
4725
  }]);
4712
4726
 
4713
4727
  return ObservableSet;
4714
- }(); // eslint-disable-next-line
4728
+ }(_Symbol$iterator$1, _Symbol$toStringTag$1); // eslint-disable-next-line
4715
4729
 
4716
4730
  var isObservableSet = /*#__PURE__*/createInstanceofPredicate("ObservableSet", ObservableSet);
4717
4731
 
@@ -4897,7 +4911,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4897
4911
  // When called from super() some props may not exist yet.
4898
4912
  // However we don't have to worry about missing prop,
4899
4913
  // because the decorator must have been applied to something.
4900
- 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]) {
4901
4915
  return; // will be annotated by subclass constructor
4902
4916
  } else {
4903
4917
  die(1, annotation.annotationType_, this.name_ + "." + key.toString());
@@ -5401,7 +5415,7 @@ inherit(StubArray, Array.prototype); // Weex proto freeze protection was here,
5401
5415
  // but it is unclear why the hack is need as MobX never changed the prototype
5402
5416
  // anyway, so removed it in V6
5403
5417
 
5404
- var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5418
+ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringTag, _Symbol$iterator) {
5405
5419
  _inheritsLoose(LegacyObservableArray, _StubArray);
5406
5420
 
5407
5421
  function LegacyObservableArray(initialValues, enhancer, name, owned) {
@@ -5446,7 +5460,7 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5446
5460
  }));
5447
5461
  };
5448
5462
 
5449
- _proto[Symbol.iterator] = function () {
5463
+ _proto[_Symbol$iterator] = function () {
5450
5464
  var self = this;
5451
5465
  var nextIndex = 0;
5452
5466
  return makeIterable({
@@ -5472,14 +5486,14 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5472
5486
  this[$mobx].setArrayLength_(newLength);
5473
5487
  }
5474
5488
  }, {
5475
- key: Symbol.toStringTag,
5489
+ key: _Symbol$toStringTag,
5476
5490
  get: function get() {
5477
5491
  return "Array";
5478
5492
  }
5479
5493
  }]);
5480
5494
 
5481
5495
  return LegacyObservableArray;
5482
- }(StubArray);
5496
+ }(StubArray, Symbol.toStringTag, Symbol.iterator);
5483
5497
 
5484
5498
  Object.entries(arrayExtensions).forEach(function (_ref) {
5485
5499
  var prop = _ref[0],
@@ -5602,7 +5616,7 @@ function eq(a, b, depth, aStack, bStack) {
5602
5616
  if (a !== a) return b !== b; // Exhaust primitive checks
5603
5617
 
5604
5618
  var type = typeof a;
5605
- if (!isFunction(type) && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5619
+ if (type !== "function" && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5606
5620
 
5607
5621
  var className = toString.call(a);
5608
5622
  if (className !== toString.call(b)) return false;