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.
@@ -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
 
@@ -3327,7 +3335,7 @@
3327
3335
 
3328
3336
  cancel = function cancel() {
3329
3337
  disposer();
3330
- reject("WHEN_CANCELLED");
3338
+ reject(new Error("WHEN_CANCELLED"));
3331
3339
  };
3332
3340
  });
3333
3341
  res.cancel = cancel;
@@ -3458,7 +3466,11 @@
3458
3466
  try {
3459
3467
  var _annotations;
3460
3468
 
3461
- // Default to decorators
3469
+ if ("development" !== "production" && annotations && target[storedAnnotationsSymbol]) {
3470
+ die("makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.");
3471
+ } // Default to decorators
3472
+
3473
+
3462
3474
  (_annotations = annotations) != null ? _annotations : annotations = collectStoredAnnotations(target); // Annotate
3463
3475
 
3464
3476
  ownKeys(annotations).forEach(function (key) {
@@ -3681,9 +3693,12 @@
3681
3693
 
3682
3694
  return (_this$values_ = this.values_).splice.apply(_this$values_, [index, deleteCount].concat(newItems));
3683
3695
  } else {
3684
- var res = this.values_.slice(index, index + deleteCount);
3685
- var oldItems = this.values_.slice(index + deleteCount);
3686
- this.values_.length = index + newItems.length - deleteCount;
3696
+ // The items removed by the splice
3697
+ var res = this.values_.slice(index, index + deleteCount); // The items that that should remain at the end of the array
3698
+
3699
+ var oldItems = this.values_.slice(index + deleteCount); // New length is the previous length + addition count - deletion count
3700
+
3701
+ this.values_.length += newItems.length - deleteCount;
3687
3702
 
3688
3703
  for (var i = 0; i < newItems.length; i++) {
3689
3704
  this.values_[index + i] = newItems[i];
@@ -4000,7 +4015,7 @@
4000
4015
 
4001
4016
  _Symbol$iterator = Symbol.iterator;
4002
4017
  _Symbol$toStringTag = Symbol.toStringTag;
4003
- var ObservableMap = /*#__PURE__*/function () {
4018
+ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4004
4019
  // hasMap, not hashMap >-).
4005
4020
  function ObservableMap(initialData, enhancer_, name_) {
4006
4021
  if (enhancer_ === void 0) {
@@ -4106,7 +4121,8 @@
4106
4121
  name: key
4107
4122
  } : null;
4108
4123
 
4109
- if ( notifySpy) spyReportStart(_change);
4124
+ if ( notifySpy) spyReportStart(_change); // TODO fix type
4125
+
4110
4126
  transaction(function () {
4111
4127
  var _this2$hasMap_$get;
4112
4128
 
@@ -4144,7 +4160,8 @@
4144
4160
  name: key,
4145
4161
  newValue: newValue
4146
4162
  } : null;
4147
- if ( notifySpy) spyReportStart(change);
4163
+ if ( notifySpy) spyReportStart(change); // TODO fix type
4164
+
4148
4165
  observable.setNewValue_(newValue);
4149
4166
  if (notify) notifyListeners(this, change);
4150
4167
  if ( notifySpy) spyReportEnd();
@@ -4178,7 +4195,8 @@
4178
4195
  name: key,
4179
4196
  newValue: newValue
4180
4197
  } : null;
4181
- if ( notifySpy) spyReportStart(change);
4198
+ if ( notifySpy) spyReportStart(change); // TODO fix type
4199
+
4182
4200
  if (notify) notifyListeners(this, change);
4183
4201
  if ( notifySpy) spyReportEnd();
4184
4202
  };
@@ -4235,7 +4253,7 @@
4235
4253
  });
4236
4254
  };
4237
4255
 
4238
- _proto[_Symbol$iterator] = function () {
4256
+ _proto[_Symbol$iterator2] = function () {
4239
4257
  return this.entries();
4240
4258
  };
4241
4259
 
@@ -4415,14 +4433,14 @@
4415
4433
  return this.data_.size;
4416
4434
  }
4417
4435
  }, {
4418
- key: _Symbol$toStringTag,
4436
+ key: _Symbol$toStringTag2,
4419
4437
  get: function get() {
4420
4438
  return "Map";
4421
4439
  }
4422
4440
  }]);
4423
4441
 
4424
4442
  return ObservableMap;
4425
- }(); // eslint-disable-next-line
4443
+ }(_Symbol$iterator, _Symbol$toStringTag); // eslint-disable-next-line
4426
4444
 
4427
4445
  var isObservableMap = /*#__PURE__*/createInstanceofPredicate("ObservableMap", ObservableMap);
4428
4446
 
@@ -4448,7 +4466,7 @@
4448
4466
  var ObservableSetMarker = {};
4449
4467
  _Symbol$iterator$1 = Symbol.iterator;
4450
4468
  _Symbol$toStringTag$1 = Symbol.toStringTag;
4451
- var ObservableSet = /*#__PURE__*/function () {
4469
+ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4452
4470
  function ObservableSet(initialData, enhancer, name_) {
4453
4471
  if (enhancer === void 0) {
4454
4472
  enhancer = deepEnhancer;
@@ -4681,7 +4699,7 @@
4681
4699
  return "[object ObservableSet]";
4682
4700
  };
4683
4701
 
4684
- _proto[_Symbol$iterator$1] = function () {
4702
+ _proto[_Symbol$iterator2] = function () {
4685
4703
  return this.values();
4686
4704
  };
4687
4705
 
@@ -4692,14 +4710,14 @@
4692
4710
  return this.data_.size;
4693
4711
  }
4694
4712
  }, {
4695
- key: _Symbol$toStringTag$1,
4713
+ key: _Symbol$toStringTag2,
4696
4714
  get: function get() {
4697
4715
  return "Set";
4698
4716
  }
4699
4717
  }]);
4700
4718
 
4701
4719
  return ObservableSet;
4702
- }(); // eslint-disable-next-line
4720
+ }(_Symbol$iterator$1, _Symbol$toStringTag$1); // eslint-disable-next-line
4703
4721
 
4704
4722
  var isObservableSet = /*#__PURE__*/createInstanceofPredicate("ObservableSet", ObservableSet);
4705
4723
 
@@ -4885,7 +4903,7 @@
4885
4903
  // When called from super() some props may not exist yet.
4886
4904
  // However we don't have to worry about missing prop,
4887
4905
  // because the decorator must have been applied to something.
4888
- if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) == null ? void 0 : _this$target_$storedA[key]) {
4906
+ if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) != null && _this$target_$storedA[key]) {
4889
4907
  return; // will be annotated by subclass constructor
4890
4908
  } else {
4891
4909
  die(1, annotation.annotationType_, this.name_ + "." + key.toString());
@@ -5389,7 +5407,7 @@
5389
5407
  // but it is unclear why the hack is need as MobX never changed the prototype
5390
5408
  // anyway, so removed it in V6
5391
5409
 
5392
- var LegacyObservableArray = /*#__PURE__*/function (_StubArray) {
5410
+ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringTag, _Symbol$iterator) {
5393
5411
  _inheritsLoose(LegacyObservableArray, _StubArray);
5394
5412
 
5395
5413
  function LegacyObservableArray(initialValues, enhancer, name, owned) {
@@ -5434,7 +5452,7 @@
5434
5452
  }));
5435
5453
  };
5436
5454
 
5437
- _proto[Symbol.iterator] = function () {
5455
+ _proto[_Symbol$iterator] = function () {
5438
5456
  var self = this;
5439
5457
  var nextIndex = 0;
5440
5458
  return makeIterable({
@@ -5460,14 +5478,14 @@
5460
5478
  this[$mobx].setArrayLength_(newLength);
5461
5479
  }
5462
5480
  }, {
5463
- key: Symbol.toStringTag,
5481
+ key: _Symbol$toStringTag,
5464
5482
  get: function get() {
5465
5483
  return "Array";
5466
5484
  }
5467
5485
  }]);
5468
5486
 
5469
5487
  return LegacyObservableArray;
5470
- }(StubArray);
5488
+ }(StubArray, Symbol.toStringTag, Symbol.iterator);
5471
5489
 
5472
5490
  Object.entries(arrayExtensions).forEach(function (_ref) {
5473
5491
  var prop = _ref[0],