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/CHANGELOG.md +12 -0
- package/dist/core/reaction.d.ts +1 -0
- package/dist/mobx.cjs.development.js +14 -11
- package/dist/mobx.cjs.development.js.map +1 -1
- package/dist/mobx.cjs.production.min.js +1 -1
- package/dist/mobx.cjs.production.min.js.map +1 -1
- package/dist/mobx.esm.development.js +14 -11
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +14 -11
- package/dist/mobx.esm.js.map +1 -1
- package/dist/mobx.esm.production.min.js +1 -1
- package/dist/mobx.esm.production.min.js.map +1 -1
- package/dist/mobx.mjs +14 -11
- package/dist/mobx.mjs.map +1 -1
- package/dist/mobx.umd.development.js +14 -11
- package/dist/mobx.umd.development.js.map +1 -1
- package/dist/mobx.umd.production.min.js +1 -1
- package/dist/mobx.umd.production.min.js.map +1 -1
- package/package.json +1 -1
- package/src/core/reaction.ts +8 -5
- package/src/types/observablearray.ts +2 -3
- package/src/types/observableset.ts +2 -1
- package/src/types/observablevalue.ts +1 -1
package/package.json
CHANGED
package/src/core/reaction.ts
CHANGED
|
@@ -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
|
-
|
|
236
|
-
abortSignal
|
|
237
|
-
|
|
238
|
-
|
|
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 (
|
|
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.
|
|
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()
|