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.
@@ -170,12 +170,11 @@
170
170
  return value !== null && typeof value === "object";
171
171
  }
172
172
  function isPlainObject(value) {
173
- var _proto$constructor;
174
-
175
173
  if (!isObject(value)) return false;
176
174
  var proto = Object.getPrototypeOf(value);
177
175
  if (proto == null) return true;
178
- return ((_proto$constructor = proto.constructor) == null ? void 0 : _proto$constructor.toString()) === plainObjectString;
176
+ var protoConstructor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
177
+ return typeof protoConstructor === "function" && protoConstructor.toString() === plainObjectString;
179
178
  } // https://stackoverflow.com/a/37865170
180
179
 
181
180
  function isGenerator(obj) {
@@ -270,6 +269,9 @@
270
269
  function _createClass(Constructor, protoProps, staticProps) {
271
270
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
272
271
  if (staticProps) _defineProperties(Constructor, staticProps);
272
+ Object.defineProperty(Constructor, "prototype", {
273
+ writable: false
274
+ });
273
275
  return Constructor;
274
276
  }
275
277
 
@@ -294,7 +296,17 @@
294
296
  function _inheritsLoose(subClass, superClass) {
295
297
  subClass.prototype = Object.create(superClass.prototype);
296
298
  subClass.prototype.constructor = subClass;
297
- subClass.__proto__ = superClass;
299
+
300
+ _setPrototypeOf(subClass, superClass);
301
+ }
302
+
303
+ function _setPrototypeOf(o, p) {
304
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
305
+ o.__proto__ = p;
306
+ return o;
307
+ };
308
+
309
+ return _setPrototypeOf(o, p);
298
310
  }
299
311
 
300
312
  function _assertThisInitialized(self) {
@@ -323,28 +335,24 @@
323
335
  }
324
336
 
325
337
  function _createForOfIteratorHelperLoose(o, allowArrayLike) {
326
- var it;
327
-
328
- if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
329
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
330
- if (it) o = it;
331
- var i = 0;
332
- return function () {
333
- if (i >= o.length) return {
334
- done: true
335
- };
336
- return {
337
- done: false,
338
- value: o[i++]
339
- };
338
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
339
+ if (it) return (it = it.call(o)).next.bind(it);
340
+
341
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
342
+ if (it) o = it;
343
+ var i = 0;
344
+ return function () {
345
+ if (i >= o.length) return {
346
+ done: true
340
347
  };
341
- }
342
-
343
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
348
+ return {
349
+ done: false,
350
+ value: o[i++]
351
+ };
352
+ };
344
353
  }
345
354
 
346
- it = o[Symbol.iterator]();
347
- return it.next.bind(it);
355
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
348
356
  }
349
357
 
350
358
  var storedAnnotationsSymbol = /*#__PURE__*/Symbol("mobx-stored-annotations");
@@ -628,7 +636,7 @@
628
636
  var _this$options_;
629
637
 
630
638
  // bound
631
- if ((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) {
639
+ if ((_this$options_ = this.options_) != null && _this$options_.bound) {
632
640
  return this.extend_(adm, key, descriptor, false) === null ? 0
633
641
  /* Cancel */
634
642
  : 1
@@ -686,7 +694,7 @@
686
694
  assertActionDescriptor(adm, annotation, key, descriptor);
687
695
  var value = descriptor.value;
688
696
 
689
- if ((_annotation$options_ = annotation.options_) == null ? void 0 : _annotation$options_.bound) {
697
+ if ((_annotation$options_ = annotation.options_) != null && _annotation$options_.bound) {
690
698
  var _adm$proxy_;
691
699
 
692
700
  value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
@@ -694,7 +702,7 @@
694
702
 
695
703
  return {
696
704
  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
697
- ((_annotation$options_4 = annotation.options_) == null ? void 0 : _annotation$options_4.bound) ? (_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_ : undefined),
705
+ (_annotation$options_4 = annotation.options_) != null && _annotation$options_4.bound ? (_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_ : undefined),
698
706
  // Non-configurable for classes
699
707
  // prevents accidental field redefinition in subclass
700
708
  configurable: safeDescriptors ? adm.isPlainObject_ : true,
@@ -729,7 +737,7 @@
729
737
  // bound - must annotate protos to support super.flow()
730
738
 
731
739
 
732
- if (((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) && !isFlow(adm.target_[key])) {
740
+ if ((_this$options_ = this.options_) != null && _this$options_.bound && !isFlow(adm.target_[key])) {
733
741
  if (this.extend_(adm, key, descriptor, false) === null) return 0
734
742
  /* Cancel */
735
743
  ;
@@ -912,11 +920,11 @@
912
920
  if (isGenerator(descriptor.value)) {
913
921
  var _this$options_;
914
922
 
915
- var flowAnnotation = ((_this$options_ = this.options_) == null ? void 0 : _this$options_.autoBind) ? flow.bound : flow;
923
+ var flowAnnotation = (_this$options_ = this.options_) != null && _this$options_.autoBind ? flow.bound : flow;
916
924
  return flowAnnotation.make_(adm, key, descriptor, source);
917
925
  }
918
926
 
919
- var actionAnnotation = ((_this$options_2 = this.options_) == null ? void 0 : _this$options_2.autoBind) ? autoAction.bound : autoAction;
927
+ var actionAnnotation = (_this$options_2 = this.options_) != null && _this$options_2.autoBind ? autoAction.bound : autoAction;
920
928
  return actionAnnotation.make_(adm, key, descriptor, source);
921
929
  } // other -> observable
922
930
  // Copy props from proto as well, see test:
@@ -925,7 +933,7 @@
925
933
 
926
934
  var observableAnnotation = ((_this$options_3 = this.options_) == null ? void 0 : _this$options_3.deep) === false ? observable.ref : observable; // if function respect autoBind option
927
935
 
928
- if (typeof descriptor.value === "function" && ((_this$options_4 = this.options_) == null ? void 0 : _this$options_4.autoBind)) {
936
+ if (typeof descriptor.value === "function" && (_this$options_4 = this.options_) != null && _this$options_4.autoBind) {
929
937
  var _adm$proxy_;
930
938
 
931
939
  descriptor.value = descriptor.value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
@@ -953,7 +961,7 @@
953
961
  // if function respect autoBind option
954
962
 
955
963
 
956
- if (typeof descriptor.value === "function" && ((_this$options_5 = this.options_) == null ? void 0 : _this$options_5.autoBind)) {
964
+ if (typeof descriptor.value === "function" && (_this$options_5 = this.options_) != null && _this$options_5.autoBind) {
957
965
  var _adm$proxy_2;
958
966
 
959
967
  descriptor.value = descriptor.value.bind((_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_);
@@ -1231,7 +1239,7 @@
1231
1239
  var _Symbol$toPrimitive;
1232
1240
  var CREATE = "create";
1233
1241
  _Symbol$toPrimitive = Symbol.toPrimitive;
1234
- var ObservableValue = /*#__PURE__*/function (_Atom) {
1242
+ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
1235
1243
  _inheritsLoose(ObservableValue, _Atom);
1236
1244
 
1237
1245
  function ObservableValue(value, enhancer, name_, notifySpy, equals) {
@@ -1378,12 +1386,12 @@
1378
1386
  return toPrimitive(this.get());
1379
1387
  };
1380
1388
 
1381
- _proto[_Symbol$toPrimitive] = function () {
1389
+ _proto[_Symbol$toPrimitive2] = function () {
1382
1390
  return this.valueOf();
1383
1391
  };
1384
1392
 
1385
1393
  return ObservableValue;
1386
- }(Atom);
1394
+ }(Atom, _Symbol$toPrimitive);
1387
1395
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1388
1396
 
1389
1397
  var _Symbol$toPrimitive$1;
@@ -1408,7 +1416,7 @@
1408
1416
  */
1409
1417
 
1410
1418
  _Symbol$toPrimitive$1 = Symbol.toPrimitive;
1411
- var ComputedValue = /*#__PURE__*/function () {
1419
+ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
1412
1420
  // nodes we are looking at. Our value depends on these nodes
1413
1421
  // during tracking it's an array with new observed observers
1414
1422
  // to check for cycles
@@ -1462,7 +1470,7 @@
1462
1470
 
1463
1471
  this.equals_ = options.equals || (options.compareStructural || options.struct ? comparer.structural : comparer["default"]);
1464
1472
  this.scope_ = options.context;
1465
- this.requiresReaction_ = !!options.requiresReaction;
1473
+ this.requiresReaction_ = options.requiresReaction;
1466
1474
  this.keepAlive_ = !!options.keepAlive;
1467
1475
  }
1468
1476
 
@@ -1630,7 +1638,7 @@
1630
1638
  console.log("[mobx.trace] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
1631
1639
  }
1632
1640
 
1633
- if (globalState.computedRequiresReaction || this.requiresReaction_) {
1641
+ if (typeof this.requiresReaction_ === "boolean" ? this.requiresReaction_ : globalState.computedRequiresReaction) {
1634
1642
  console.warn("[mobx] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
1635
1643
  }
1636
1644
  };
@@ -1643,12 +1651,12 @@
1643
1651
  return toPrimitive(this.get());
1644
1652
  };
1645
1653
 
1646
- _proto[_Symbol$toPrimitive$1] = function () {
1654
+ _proto[_Symbol$toPrimitive2] = function () {
1647
1655
  return this.valueOf();
1648
1656
  };
1649
1657
 
1650
1658
  return ComputedValue;
1651
- }();
1659
+ }(_Symbol$toPrimitive$1);
1652
1660
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1653
1661
 
1654
1662
  var IDerivationState_;
@@ -2189,8 +2197,8 @@
2189
2197
  }
2190
2198
  } else if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_ // this happens during computing of `d`, just keep lowestObserverState up to date.
2191
2199
  ) {
2192
- observable.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
2193
- }
2200
+ observable.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
2201
+ }
2194
2202
  }); // invariantLOS(observable, "confirmed end");
2195
2203
  } // Used by computed when its dependency changed, but we don't wan't to immediately recompute.
2196
2204
 
@@ -3218,7 +3226,10 @@
3218
3226
  }
3219
3227
  }
3220
3228
  /**
3221
- * Basically, a deep clone, so that no reactive property will exist anymore.
3229
+ * Recursively converts an observable to it's non-observable native counterpart.
3230
+ * It does NOT recurse into non-observables, these are left as they are, even if they contain observables.
3231
+ * Computed and other non-enumerable properties are completely ignored.
3232
+ * Complex scenarios require custom solution, eg implementing `toJSON` or using `serializr` lib.
3222
3233
  */
3223
3234
 
3224
3235
 
@@ -3685,9 +3696,12 @@
3685
3696
 
3686
3697
  return (_this$values_ = this.values_).splice.apply(_this$values_, [index, deleteCount].concat(newItems));
3687
3698
  } else {
3688
- var res = this.values_.slice(index, index + deleteCount);
3689
- var oldItems = this.values_.slice(index + deleteCount);
3690
- this.values_.length = index + newItems.length - deleteCount;
3699
+ // The items removed by the splice
3700
+ var res = this.values_.slice(index, index + deleteCount); // The items that that should remain at the end of the array
3701
+
3702
+ var oldItems = this.values_.slice(index + deleteCount); // New length is the previous length + addition count - deletion count
3703
+
3704
+ this.values_.length += newItems.length - deleteCount;
3691
3705
 
3692
3706
  for (var i = 0; i < newItems.length; i++) {
3693
3707
  this.values_[index + i] = newItems[i];
@@ -4004,7 +4018,7 @@
4004
4018
 
4005
4019
  _Symbol$iterator = Symbol.iterator;
4006
4020
  _Symbol$toStringTag = Symbol.toStringTag;
4007
- var ObservableMap = /*#__PURE__*/function () {
4021
+ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4008
4022
  // hasMap, not hashMap >-).
4009
4023
  function ObservableMap(initialData, enhancer_, name_) {
4010
4024
  if (enhancer_ === void 0) {
@@ -4110,7 +4124,8 @@
4110
4124
  name: key
4111
4125
  } : null;
4112
4126
 
4113
- if ( notifySpy) spyReportStart(_change);
4127
+ if ( notifySpy) spyReportStart(_change); // TODO fix type
4128
+
4114
4129
  transaction(function () {
4115
4130
  var _this2$hasMap_$get;
4116
4131
 
@@ -4148,7 +4163,8 @@
4148
4163
  name: key,
4149
4164
  newValue: newValue
4150
4165
  } : null;
4151
- if ( notifySpy) spyReportStart(change);
4166
+ if ( notifySpy) spyReportStart(change); // TODO fix type
4167
+
4152
4168
  observable.setNewValue_(newValue);
4153
4169
  if (notify) notifyListeners(this, change);
4154
4170
  if ( notifySpy) spyReportEnd();
@@ -4182,7 +4198,8 @@
4182
4198
  name: key,
4183
4199
  newValue: newValue
4184
4200
  } : null;
4185
- if ( notifySpy) spyReportStart(change);
4201
+ if ( notifySpy) spyReportStart(change); // TODO fix type
4202
+
4186
4203
  if (notify) notifyListeners(this, change);
4187
4204
  if ( notifySpy) spyReportEnd();
4188
4205
  };
@@ -4239,7 +4256,7 @@
4239
4256
  });
4240
4257
  };
4241
4258
 
4242
- _proto[_Symbol$iterator] = function () {
4259
+ _proto[_Symbol$iterator2] = function () {
4243
4260
  return this.entries();
4244
4261
  };
4245
4262
 
@@ -4419,14 +4436,14 @@
4419
4436
  return this.data_.size;
4420
4437
  }
4421
4438
  }, {
4422
- key: _Symbol$toStringTag,
4439
+ key: _Symbol$toStringTag2,
4423
4440
  get: function get() {
4424
4441
  return "Map";
4425
4442
  }
4426
4443
  }]);
4427
4444
 
4428
4445
  return ObservableMap;
4429
- }(); // eslint-disable-next-line
4446
+ }(_Symbol$iterator, _Symbol$toStringTag); // eslint-disable-next-line
4430
4447
 
4431
4448
  var isObservableMap = /*#__PURE__*/createInstanceofPredicate("ObservableMap", ObservableMap);
4432
4449
 
@@ -4452,7 +4469,7 @@
4452
4469
  var ObservableSetMarker = {};
4453
4470
  _Symbol$iterator$1 = Symbol.iterator;
4454
4471
  _Symbol$toStringTag$1 = Symbol.toStringTag;
4455
- var ObservableSet = /*#__PURE__*/function () {
4472
+ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4456
4473
  function ObservableSet(initialData, enhancer, name_) {
4457
4474
  if (enhancer === void 0) {
4458
4475
  enhancer = deepEnhancer;
@@ -4685,7 +4702,7 @@
4685
4702
  return "[object ObservableSet]";
4686
4703
  };
4687
4704
 
4688
- _proto[_Symbol$iterator$1] = function () {
4705
+ _proto[_Symbol$iterator2] = function () {
4689
4706
  return this.values();
4690
4707
  };
4691
4708
 
@@ -4696,14 +4713,14 @@
4696
4713
  return this.data_.size;
4697
4714
  }
4698
4715
  }, {
4699
- key: _Symbol$toStringTag$1,
4716
+ key: _Symbol$toStringTag2,
4700
4717
  get: function get() {
4701
4718
  return "Set";
4702
4719
  }
4703
4720
  }]);
4704
4721
 
4705
4722
  return ObservableSet;
4706
- }(); // eslint-disable-next-line
4723
+ }(_Symbol$iterator$1, _Symbol$toStringTag$1); // eslint-disable-next-line
4707
4724
 
4708
4725
  var isObservableSet = /*#__PURE__*/createInstanceofPredicate("ObservableSet", ObservableSet);
4709
4726
 
@@ -4889,7 +4906,7 @@
4889
4906
  // When called from super() some props may not exist yet.
4890
4907
  // However we don't have to worry about missing prop,
4891
4908
  // because the decorator must have been applied to something.
4892
- if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) == null ? void 0 : _this$target_$storedA[key]) {
4909
+ if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) != null && _this$target_$storedA[key]) {
4893
4910
  return; // will be annotated by subclass constructor
4894
4911
  } else {
4895
4912
  die(1, annotation.annotationType_, this.name_ + "." + key.toString());
@@ -5393,7 +5410,7 @@
5393
5410
  // but it is unclear why the hack is need as MobX never changed the prototype
5394
5411
  // anyway, so removed it in V6
5395
5412
 
5396
- var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5413
+ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringTag, _Symbol$iterator) {
5397
5414
  _inheritsLoose(LegacyObservableArray, _StubArray);
5398
5415
 
5399
5416
  function LegacyObservableArray(initialValues, enhancer, name, owned) {
@@ -5438,7 +5455,7 @@
5438
5455
  }));
5439
5456
  };
5440
5457
 
5441
- _proto[Symbol.iterator] = function () {
5458
+ _proto[_Symbol$iterator] = function () {
5442
5459
  var self = this;
5443
5460
  var nextIndex = 0;
5444
5461
  return makeIterable({
@@ -5464,14 +5481,14 @@
5464
5481
  this[$mobx].setArrayLength_(newLength);
5465
5482
  }
5466
5483
  }, {
5467
- key: Symbol.toStringTag,
5484
+ key: _Symbol$toStringTag,
5468
5485
  get: function get() {
5469
5486
  return "Array";
5470
5487
  }
5471
5488
  }]);
5472
5489
 
5473
5490
  return LegacyObservableArray;
5474
- }(StubArray);
5491
+ }(StubArray, Symbol.toStringTag, Symbol.iterator);
5475
5492
 
5476
5493
  Object.entries(arrayExtensions).forEach(function (_ref) {
5477
5494
  var prop = _ref[0],
@@ -5594,7 +5611,7 @@
5594
5611
  if (a !== a) return b !== b; // Exhaust primitive checks
5595
5612
 
5596
5613
  var type = typeof a;
5597
- if (!isFunction(type) && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5614
+ if (type !== "function" && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5598
5615
 
5599
5616
  var className = toString.call(a);
5600
5617
  if (className !== toString.call(b)) return false;