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.
@@ -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
 
@@ -3212,7 +3220,10 @@ function toJSHelper(source, __alreadySeen) {
3212
3220
  }
3213
3221
  }
3214
3222
  /**
3215
- * Basically, a deep clone, so that no reactive property will exist anymore.
3223
+ * Recursively converts an observable to it's non-observable native counterpart.
3224
+ * It does NOT recurse into non-observables, these are left as they are, even if they contain observables.
3225
+ * Computed and other non-enumerable properties are completely ignored.
3226
+ * Complex scenarios require custom solution, eg implementing `toJSON` or using `serializr` lib.
3216
3227
  */
3217
3228
 
3218
3229
 
@@ -3679,9 +3690,12 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
3679
3690
 
3680
3691
  return (_this$values_ = this.values_).splice.apply(_this$values_, [index, deleteCount].concat(newItems));
3681
3692
  } else {
3682
- var res = this.values_.slice(index, index + deleteCount);
3683
- var oldItems = this.values_.slice(index + deleteCount);
3684
- this.values_.length = index + newItems.length - deleteCount;
3693
+ // The items removed by the splice
3694
+ var res = this.values_.slice(index, index + deleteCount); // The items that that should remain at the end of the array
3695
+
3696
+ var oldItems = this.values_.slice(index + deleteCount); // New length is the previous length + addition count - deletion count
3697
+
3698
+ this.values_.length += newItems.length - deleteCount;
3685
3699
 
3686
3700
  for (var i = 0; i < newItems.length; i++) {
3687
3701
  this.values_[index + i] = newItems[i];
@@ -3998,7 +4012,7 @@ var DELETE = "delete"; // just extend Map? See also https://gist.github.com/nest
3998
4012
 
3999
4013
  _Symbol$iterator = Symbol.iterator;
4000
4014
  _Symbol$toStringTag = Symbol.toStringTag;
4001
- var ObservableMap = /*#__PURE__*/function () {
4015
+ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4002
4016
  // hasMap, not hashMap >-).
4003
4017
  function ObservableMap(initialData, enhancer_, name_) {
4004
4018
  if (enhancer_ === void 0) {
@@ -4104,7 +4118,8 @@ var ObservableMap = /*#__PURE__*/function () {
4104
4118
  name: key
4105
4119
  } : null;
4106
4120
 
4107
- if ( notifySpy) spyReportStart(_change);
4121
+ if ( notifySpy) spyReportStart(_change); // TODO fix type
4122
+
4108
4123
  transaction(function () {
4109
4124
  var _this2$hasMap_$get;
4110
4125
 
@@ -4142,7 +4157,8 @@ var ObservableMap = /*#__PURE__*/function () {
4142
4157
  name: key,
4143
4158
  newValue: newValue
4144
4159
  } : null;
4145
- if ( notifySpy) spyReportStart(change);
4160
+ if ( notifySpy) spyReportStart(change); // TODO fix type
4161
+
4146
4162
  observable.setNewValue_(newValue);
4147
4163
  if (notify) notifyListeners(this, change);
4148
4164
  if ( notifySpy) spyReportEnd();
@@ -4176,7 +4192,8 @@ var ObservableMap = /*#__PURE__*/function () {
4176
4192
  name: key,
4177
4193
  newValue: newValue
4178
4194
  } : null;
4179
- if ( notifySpy) spyReportStart(change);
4195
+ if ( notifySpy) spyReportStart(change); // TODO fix type
4196
+
4180
4197
  if (notify) notifyListeners(this, change);
4181
4198
  if ( notifySpy) spyReportEnd();
4182
4199
  };
@@ -4233,7 +4250,7 @@ var ObservableMap = /*#__PURE__*/function () {
4233
4250
  });
4234
4251
  };
4235
4252
 
4236
- _proto[_Symbol$iterator] = function () {
4253
+ _proto[_Symbol$iterator2] = function () {
4237
4254
  return this.entries();
4238
4255
  };
4239
4256
 
@@ -4413,14 +4430,14 @@ var ObservableMap = /*#__PURE__*/function () {
4413
4430
  return this.data_.size;
4414
4431
  }
4415
4432
  }, {
4416
- key: _Symbol$toStringTag,
4433
+ key: _Symbol$toStringTag2,
4417
4434
  get: function get() {
4418
4435
  return "Map";
4419
4436
  }
4420
4437
  }]);
4421
4438
 
4422
4439
  return ObservableMap;
4423
- }(); // eslint-disable-next-line
4440
+ }(_Symbol$iterator, _Symbol$toStringTag); // eslint-disable-next-line
4424
4441
 
4425
4442
  var isObservableMap = /*#__PURE__*/createInstanceofPredicate("ObservableMap", ObservableMap);
4426
4443
 
@@ -4446,7 +4463,7 @@ var _Symbol$iterator$1, _Symbol$toStringTag$1;
4446
4463
  var ObservableSetMarker = {};
4447
4464
  _Symbol$iterator$1 = Symbol.iterator;
4448
4465
  _Symbol$toStringTag$1 = Symbol.toStringTag;
4449
- var ObservableSet = /*#__PURE__*/function () {
4466
+ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4450
4467
  function ObservableSet(initialData, enhancer, name_) {
4451
4468
  if (enhancer === void 0) {
4452
4469
  enhancer = deepEnhancer;
@@ -4679,7 +4696,7 @@ var ObservableSet = /*#__PURE__*/function () {
4679
4696
  return "[object ObservableSet]";
4680
4697
  };
4681
4698
 
4682
- _proto[_Symbol$iterator$1] = function () {
4699
+ _proto[_Symbol$iterator2] = function () {
4683
4700
  return this.values();
4684
4701
  };
4685
4702
 
@@ -4690,14 +4707,14 @@ var ObservableSet = /*#__PURE__*/function () {
4690
4707
  return this.data_.size;
4691
4708
  }
4692
4709
  }, {
4693
- key: _Symbol$toStringTag$1,
4710
+ key: _Symbol$toStringTag2,
4694
4711
  get: function get() {
4695
4712
  return "Set";
4696
4713
  }
4697
4714
  }]);
4698
4715
 
4699
4716
  return ObservableSet;
4700
- }(); // eslint-disable-next-line
4717
+ }(_Symbol$iterator$1, _Symbol$toStringTag$1); // eslint-disable-next-line
4701
4718
 
4702
4719
  var isObservableSet = /*#__PURE__*/createInstanceofPredicate("ObservableSet", ObservableSet);
4703
4720
 
@@ -4883,7 +4900,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4883
4900
  // When called from super() some props may not exist yet.
4884
4901
  // However we don't have to worry about missing prop,
4885
4902
  // because the decorator must have been applied to something.
4886
- if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) == null ? void 0 : _this$target_$storedA[key]) {
4903
+ if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) != null && _this$target_$storedA[key]) {
4887
4904
  return; // will be annotated by subclass constructor
4888
4905
  } else {
4889
4906
  die(1, annotation.annotationType_, this.name_ + "." + key.toString());
@@ -5387,7 +5404,7 @@ inherit(StubArray, Array.prototype); // Weex proto freeze protection was here,
5387
5404
  // but it is unclear why the hack is need as MobX never changed the prototype
5388
5405
  // anyway, so removed it in V6
5389
5406
 
5390
- var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5407
+ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringTag, _Symbol$iterator) {
5391
5408
  _inheritsLoose(LegacyObservableArray, _StubArray);
5392
5409
 
5393
5410
  function LegacyObservableArray(initialValues, enhancer, name, owned) {
@@ -5432,7 +5449,7 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5432
5449
  }));
5433
5450
  };
5434
5451
 
5435
- _proto[Symbol.iterator] = function () {
5452
+ _proto[_Symbol$iterator] = function () {
5436
5453
  var self = this;
5437
5454
  var nextIndex = 0;
5438
5455
  return makeIterable({
@@ -5458,14 +5475,14 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5458
5475
  this[$mobx].setArrayLength_(newLength);
5459
5476
  }
5460
5477
  }, {
5461
- key: Symbol.toStringTag,
5478
+ key: _Symbol$toStringTag,
5462
5479
  get: function get() {
5463
5480
  return "Array";
5464
5481
  }
5465
5482
  }]);
5466
5483
 
5467
5484
  return LegacyObservableArray;
5468
- }(StubArray);
5485
+ }(StubArray, Symbol.toStringTag, Symbol.iterator);
5469
5486
 
5470
5487
  Object.entries(arrayExtensions).forEach(function (_ref) {
5471
5488
  var prop = _ref[0],
@@ -5588,7 +5605,7 @@ function eq(a, b, depth, aStack, bStack) {
5588
5605
  if (a !== a) return b !== b; // Exhaust primitive checks
5589
5606
 
5590
5607
  var type = typeof a;
5591
- if (!isFunction(type) && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5608
+ if (type !== "function" && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5592
5609
 
5593
5610
  var className = toString.call(a);
5594
5611
  if (className !== toString.call(b)) return false;