mobx 7.0.5 → 7.0.6

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.
@@ -1191,14 +1191,13 @@ class ObservableValue extends Atom {
1191
1191
  this.equals_ = equals_;
1192
1192
  this.value_ = enhancer_(value, undefined, name_);
1193
1193
  if (notifySpy && isSpyEnabled()) {
1194
- var _this$value_;
1195
1194
  // only notify spy if this is a stand-alone observable
1196
1195
  spyReport({
1197
1196
  type: CREATE,
1198
1197
  object: this,
1199
1198
  observableKind: "value",
1200
1199
  debugObjectName: this.name_,
1201
- newValue: "" + ((_this$value_ = this.value_) == null ? void 0 : _this$value_.toString())
1200
+ newValue: this.value_
1202
1201
  });
1203
1202
  }
1204
1203
  }
@@ -2161,6 +2160,7 @@ class Reaction {
2161
2160
  this.runId_ = 0;
2162
2161
  this.unboundDepsCount_ = 0;
2163
2162
  this.flags_ = 0b00000;
2163
+ this.removeAbortListener_ = undefined;
2164
2164
  this.name_ = name_;
2165
2165
  this.onInvalidate_ = onInvalidate_;
2166
2166
  this.errorHandler_ = errorHandler_;
@@ -2297,7 +2297,10 @@ class Reaction {
2297
2297
  }
2298
2298
  dispose() {
2299
2299
  if (!this.isDisposed) {
2300
+ var _this$removeAbortList;
2300
2301
  this.isDisposed = true;
2302
+ // also covers self-disposal (`r.dispose()`, `when`), which bypasses the disposer
2303
+ (_this$removeAbortList = this.removeAbortListener_) == null || _this$removeAbortList.call(this);
2301
2304
  if (!this.isRunning) {
2302
2305
  // if disposed while running, clean up later. Maybe not optimal, but rare case
2303
2306
  startBatch();
@@ -2307,11 +2310,11 @@ class Reaction {
2307
2310
  }
2308
2311
  }
2309
2312
  getDisposer_(abortSignal) {
2310
- const dispose = () => {
2311
- this.dispose();
2312
- abortSignal == null || abortSignal.removeEventListener == null || abortSignal.removeEventListener("abort", dispose);
2313
- };
2314
- abortSignal == null || abortSignal.addEventListener == null || abortSignal.addEventListener("abort", dispose);
2313
+ const dispose = () => this.dispose();
2314
+ if (abortSignal != null && abortSignal.addEventListener && !this.isDisposed) {
2315
+ abortSignal.addEventListener("abort", dispose);
2316
+ this.removeAbortListener_ = () => abortSignal.removeEventListener == null ? void 0 : abortSignal.removeEventListener("abort", dispose);
2317
+ }
2315
2318
  dispose[$mobx] = this;
2316
2319
  if ("dispose" in Symbol && typeof Symbol.dispose === "symbol") {
2317
2320
  dispose[Symbol.dispose] = dispose;
@@ -3468,8 +3471,7 @@ const arrayTraps = {
3468
3471
  const adm = target[$mobx];
3469
3472
  if (name === "length") {
3470
3473
  adm.setArrayLength_(value);
3471
- }
3472
- if (typeof name === "symbol" || isNaN(name)) {
3474
+ } else if (typeof name === "symbol" || isNaN(name)) {
3473
3475
  target[name] = value;
3474
3476
  } else {
3475
3477
  // numeric string
@@ -3514,7 +3516,7 @@ class ObservableArrayAdministration {
3514
3516
  return this.values_.length;
3515
3517
  }
3516
3518
  setArrayLength_(newLength) {
3517
- if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) {
3519
+ if (!Number.isInteger(newLength) || newLength < 0) {
3518
3520
  die(40, newLength);
3519
3521
  }
3520
3522
  let currentLength = this.values_.length;
@@ -4296,7 +4298,8 @@ class ObservableSet {
4296
4298
  }
4297
4299
  if (!this.has(value)) {
4298
4300
  transaction(() => {
4299
- this.data_.add(this.enhancer_(value, undefined));
4301
+ value = this.enhancer_(value, undefined); // report the stored value, like map and array
4302
+ this.data_.add(value);
4300
4303
  this.atom_.reportChanged();
4301
4304
  });
4302
4305
  const notifySpy = isSpyEnabled();