mobx 6.3.7 → 6.3.11

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
 
@@ -3225,7 +3233,10 @@ function toJSHelper(source, __alreadySeen) {
3225
3233
  }
3226
3234
  }
3227
3235
  /**
3228
- * Basically, a deep clone, so that no reactive property will exist anymore.
3236
+ * Recursively converts an observable to it's non-observable native counterpart.
3237
+ * It does NOT recurse into non-observables, these are left as they are, even if they contain observables.
3238
+ * Computed and other non-enumerable properties are completely ignored.
3239
+ * Complex scenarios require custom solution, eg implementing `toJSON` or using `serializr` lib.
3229
3240
  */
3230
3241
 
3231
3242
 
@@ -3693,9 +3704,12 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
3693
3704
 
3694
3705
  return (_this$values_ = this.values_).splice.apply(_this$values_, [index, deleteCount].concat(newItems));
3695
3706
  } 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;
3707
+ // The items removed by the splice
3708
+ var res = this.values_.slice(index, index + deleteCount); // The items that that should remain at the end of the array
3709
+
3710
+ var oldItems = this.values_.slice(index + deleteCount); // New length is the previous length + addition count - deletion count
3711
+
3712
+ this.values_.length += newItems.length - deleteCount;
3699
3713
 
3700
3714
  for (var i = 0; i < newItems.length; i++) {
3701
3715
  this.values_[index + i] = newItems[i];
@@ -4012,7 +4026,7 @@ var DELETE = "delete"; // just extend Map? See also https://gist.github.com/nest
4012
4026
 
4013
4027
  _Symbol$iterator = Symbol.iterator;
4014
4028
  _Symbol$toStringTag = Symbol.toStringTag;
4015
- var ObservableMap = /*#__PURE__*/function () {
4029
+ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4016
4030
  // hasMap, not hashMap >-).
4017
4031
  function ObservableMap(initialData, enhancer_, name_) {
4018
4032
  if (enhancer_ === void 0) {
@@ -4118,7 +4132,8 @@ var ObservableMap = /*#__PURE__*/function () {
4118
4132
  name: key
4119
4133
  } : null;
4120
4134
 
4121
- if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(_change);
4135
+ if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(_change); // TODO fix type
4136
+
4122
4137
  transaction(function () {
4123
4138
  var _this2$hasMap_$get;
4124
4139
 
@@ -4156,7 +4171,8 @@ var ObservableMap = /*#__PURE__*/function () {
4156
4171
  name: key,
4157
4172
  newValue: newValue
4158
4173
  } : null;
4159
- if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(change);
4174
+ if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(change); // TODO fix type
4175
+
4160
4176
  observable.setNewValue_(newValue);
4161
4177
  if (notify) notifyListeners(this, change);
4162
4178
  if (process.env.NODE_ENV !== "production" && notifySpy) spyReportEnd();
@@ -4190,7 +4206,8 @@ var ObservableMap = /*#__PURE__*/function () {
4190
4206
  name: key,
4191
4207
  newValue: newValue
4192
4208
  } : null;
4193
- if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(change);
4209
+ if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(change); // TODO fix type
4210
+
4194
4211
  if (notify) notifyListeners(this, change);
4195
4212
  if (process.env.NODE_ENV !== "production" && notifySpy) spyReportEnd();
4196
4213
  };
@@ -4247,7 +4264,7 @@ var ObservableMap = /*#__PURE__*/function () {
4247
4264
  });
4248
4265
  };
4249
4266
 
4250
- _proto[_Symbol$iterator] = function () {
4267
+ _proto[_Symbol$iterator2] = function () {
4251
4268
  return this.entries();
4252
4269
  };
4253
4270
 
@@ -4427,14 +4444,14 @@ var ObservableMap = /*#__PURE__*/function () {
4427
4444
  return this.data_.size;
4428
4445
  }
4429
4446
  }, {
4430
- key: _Symbol$toStringTag,
4447
+ key: _Symbol$toStringTag2,
4431
4448
  get: function get() {
4432
4449
  return "Map";
4433
4450
  }
4434
4451
  }]);
4435
4452
 
4436
4453
  return ObservableMap;
4437
- }(); // eslint-disable-next-line
4454
+ }(_Symbol$iterator, _Symbol$toStringTag); // eslint-disable-next-line
4438
4455
 
4439
4456
  var isObservableMap = /*#__PURE__*/createInstanceofPredicate("ObservableMap", ObservableMap);
4440
4457
 
@@ -4460,7 +4477,7 @@ var _Symbol$iterator$1, _Symbol$toStringTag$1;
4460
4477
  var ObservableSetMarker = {};
4461
4478
  _Symbol$iterator$1 = Symbol.iterator;
4462
4479
  _Symbol$toStringTag$1 = Symbol.toStringTag;
4463
- var ObservableSet = /*#__PURE__*/function () {
4480
+ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4464
4481
  function ObservableSet(initialData, enhancer, name_) {
4465
4482
  if (enhancer === void 0) {
4466
4483
  enhancer = deepEnhancer;
@@ -4693,7 +4710,7 @@ var ObservableSet = /*#__PURE__*/function () {
4693
4710
  return "[object ObservableSet]";
4694
4711
  };
4695
4712
 
4696
- _proto[_Symbol$iterator$1] = function () {
4713
+ _proto[_Symbol$iterator2] = function () {
4697
4714
  return this.values();
4698
4715
  };
4699
4716
 
@@ -4704,14 +4721,14 @@ var ObservableSet = /*#__PURE__*/function () {
4704
4721
  return this.data_.size;
4705
4722
  }
4706
4723
  }, {
4707
- key: _Symbol$toStringTag$1,
4724
+ key: _Symbol$toStringTag2,
4708
4725
  get: function get() {
4709
4726
  return "Set";
4710
4727
  }
4711
4728
  }]);
4712
4729
 
4713
4730
  return ObservableSet;
4714
- }(); // eslint-disable-next-line
4731
+ }(_Symbol$iterator$1, _Symbol$toStringTag$1); // eslint-disable-next-line
4715
4732
 
4716
4733
  var isObservableSet = /*#__PURE__*/createInstanceofPredicate("ObservableSet", ObservableSet);
4717
4734
 
@@ -4897,7 +4914,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4897
4914
  // When called from super() some props may not exist yet.
4898
4915
  // However we don't have to worry about missing prop,
4899
4916
  // because the decorator must have been applied to something.
4900
- if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) == null ? void 0 : _this$target_$storedA[key]) {
4917
+ if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) != null && _this$target_$storedA[key]) {
4901
4918
  return; // will be annotated by subclass constructor
4902
4919
  } else {
4903
4920
  die(1, annotation.annotationType_, this.name_ + "." + key.toString());
@@ -5401,7 +5418,7 @@ inherit(StubArray, Array.prototype); // Weex proto freeze protection was here,
5401
5418
  // but it is unclear why the hack is need as MobX never changed the prototype
5402
5419
  // anyway, so removed it in V6
5403
5420
 
5404
- var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5421
+ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringTag, _Symbol$iterator) {
5405
5422
  _inheritsLoose(LegacyObservableArray, _StubArray);
5406
5423
 
5407
5424
  function LegacyObservableArray(initialValues, enhancer, name, owned) {
@@ -5446,7 +5463,7 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5446
5463
  }));
5447
5464
  };
5448
5465
 
5449
- _proto[Symbol.iterator] = function () {
5466
+ _proto[_Symbol$iterator] = function () {
5450
5467
  var self = this;
5451
5468
  var nextIndex = 0;
5452
5469
  return makeIterable({
@@ -5472,14 +5489,14 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5472
5489
  this[$mobx].setArrayLength_(newLength);
5473
5490
  }
5474
5491
  }, {
5475
- key: Symbol.toStringTag,
5492
+ key: _Symbol$toStringTag,
5476
5493
  get: function get() {
5477
5494
  return "Array";
5478
5495
  }
5479
5496
  }]);
5480
5497
 
5481
5498
  return LegacyObservableArray;
5482
- }(StubArray);
5499
+ }(StubArray, Symbol.toStringTag, Symbol.iterator);
5483
5500
 
5484
5501
  Object.entries(arrayExtensions).forEach(function (_ref) {
5485
5502
  var prop = _ref[0],
@@ -5602,7 +5619,7 @@ function eq(a, b, depth, aStack, bStack) {
5602
5619
  if (a !== a) return b !== b; // Exhaust primitive checks
5603
5620
 
5604
5621
  var type = typeof a;
5605
- if (!isFunction(type) && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5622
+ if (type !== "function" && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5606
5623
 
5607
5624
  var className = toString.call(a);
5608
5625
  if (className !== toString.call(b)) return false;