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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx",
3
- "version": "7.0.5",
3
+ "version": "7.0.6",
4
4
  "description": "Simple, scalable state management.",
5
5
  "source": "src/mobx.ts",
6
6
  "type": "commonjs",
@@ -66,6 +66,7 @@ export class Reaction implements IDerivation, IReactionPublic {
66
66
  unboundDepsCount_ = 0
67
67
 
68
68
  private flags_ = 0b00000
69
+ private removeAbortListener_: Lambda | undefined = undefined
69
70
 
70
71
  constructor(
71
72
  public name_: string = __DEV__ ? "Reaction@" + getNextId() : "Reaction",
@@ -221,6 +222,8 @@ export class Reaction implements IDerivation, IReactionPublic {
221
222
  dispose() {
222
223
  if (!this.isDisposed) {
223
224
  this.isDisposed = true
225
+ // also covers self-disposal (`r.dispose()`, `when`), which bypasses the disposer
226
+ this.removeAbortListener_?.()
224
227
  if (!this.isRunning) {
225
228
  // if disposed while running, clean up later. Maybe not optimal, but rare case
226
229
  startBatch()
@@ -231,11 +234,11 @@ export class Reaction implements IDerivation, IReactionPublic {
231
234
  }
232
235
 
233
236
  getDisposer_(abortSignal?: GenericAbortSignal): IReactionDisposer {
234
- const dispose = (() => {
235
- this.dispose()
236
- abortSignal?.removeEventListener?.("abort", dispose)
237
- }) as IReactionDisposer
238
- abortSignal?.addEventListener?.("abort", dispose)
237
+ const dispose = (() => this.dispose()) as IReactionDisposer
238
+ if (abortSignal?.addEventListener && !this.isDisposed) {
239
+ abortSignal.addEventListener("abort", dispose)
240
+ this.removeAbortListener_ = () => abortSignal.removeEventListener?.("abort", dispose)
241
+ }
239
242
  dispose[$mobx] = this
240
243
 
241
244
  if ("dispose" in Symbol && typeof Symbol.dispose === "symbol") {
@@ -95,8 +95,7 @@ const arrayTraps = {
95
95
  const adm: ObservableArrayAdministration = target[$mobx]
96
96
  if (name === "length") {
97
97
  adm.setArrayLength_(value)
98
- }
99
- if (typeof name === "symbol" || isNaN(name)) {
98
+ } else if (typeof name === "symbol" || isNaN(name)) {
100
99
  target[name] = value
101
100
  } else {
102
101
  // numeric string
@@ -151,7 +150,7 @@ export class ObservableArrayAdministration
151
150
  }
152
151
 
153
152
  setArrayLength_(newLength: number) {
154
- if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) {
153
+ if (!Number.isInteger(newLength) || newLength < 0) {
155
154
  die(40, newLength)
156
155
  }
157
156
  let currentLength = this.values_.length
@@ -127,7 +127,8 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
127
127
  }
128
128
  if (!this.has(value)) {
129
129
  transaction(() => {
130
- this.data_.add(this.enhancer_(value, undefined))
130
+ value = this.enhancer_(value, undefined) // report the stored value, like map and array
131
+ this.data_.add(value)
131
132
  this.atom_.reportChanged()
132
133
  })
133
134
  const notifySpy = __DEV__ && isSpyEnabled()
@@ -79,7 +79,7 @@ export class ObservableValue<T>
79
79
  object: this,
80
80
  observableKind: "value",
81
81
  debugObjectName: this.name_,
82
- newValue: "" + this.value_?.toString()
82
+ newValue: this.value_
83
83
  })
84
84
  }
85
85
  }