mobx 6.3.2 → 6.3.3
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 +17 -0
- package/README.md +3 -3
- package/dist/api/autorun.d.ts +3 -3
- package/dist/mobx.cjs.development.js +21 -16
- 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 +21 -16
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +21 -16
- 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.umd.development.js +21 -16
- 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/api/autorun.ts +5 -5
- package/src/api/observable.ts +4 -4
- package/src/api/when.ts +1 -1
- package/src/core/computedvalue.ts +8 -6
- package/src/core/derivation.ts +4 -2
- package/src/mobx.ts +1 -1
- package/src/utils/comparer.ts +5 -1
package/package.json
CHANGED
package/src/api/autorun.ts
CHANGED
|
@@ -86,14 +86,14 @@ export function autorun(
|
|
|
86
86
|
return reaction.getDisposer_()
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
export type IReactionOptions = IAutorunOptions & {
|
|
89
|
+
export type IReactionOptions<T> = IAutorunOptions & {
|
|
90
90
|
fireImmediately?: boolean
|
|
91
|
-
equals?: IEqualsComparer<
|
|
91
|
+
equals?: IEqualsComparer<T>
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
const run = (f: Lambda) => f()
|
|
95
95
|
|
|
96
|
-
function createSchedulerFromOptions(opts:
|
|
96
|
+
function createSchedulerFromOptions(opts: IAutorunOptions) {
|
|
97
97
|
return opts.scheduler
|
|
98
98
|
? opts.scheduler
|
|
99
99
|
: opts.delay
|
|
@@ -104,7 +104,7 @@ function createSchedulerFromOptions(opts: IReactionOptions) {
|
|
|
104
104
|
export function reaction<T>(
|
|
105
105
|
expression: (r: IReactionPublic) => T,
|
|
106
106
|
effect: (arg: T, prev: T, r: IReactionPublic) => void,
|
|
107
|
-
opts: IReactionOptions = EMPTY_OBJECT
|
|
107
|
+
opts: IReactionOptions<T> = EMPTY_OBJECT
|
|
108
108
|
): IReactionDisposer {
|
|
109
109
|
if (__DEV__) {
|
|
110
110
|
if (!isFunction(expression) || !isFunction(effect))
|
|
@@ -124,7 +124,7 @@ export function reaction<T>(
|
|
|
124
124
|
let value: T
|
|
125
125
|
let oldValue: T = undefined as any // only an issue with fireImmediately
|
|
126
126
|
|
|
127
|
-
const equals = (opts as any).compareStructural
|
|
127
|
+
const equals: IEqualsComparer<T> = (opts as any).compareStructural
|
|
128
128
|
? comparer.structural
|
|
129
129
|
: opts.equals || comparer.default
|
|
130
130
|
|
package/src/api/observable.ts
CHANGED
|
@@ -60,14 +60,14 @@ export function asCreateObservableOptions(thing: any): CreateObservableOptions {
|
|
|
60
60
|
return thing || defaultCreateObservableOptions
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const observableAnnotation = createObservableAnnotation(
|
|
64
|
-
const observableRefAnnotation = createObservableAnnotation(
|
|
63
|
+
const observableAnnotation = createObservableAnnotation(OBSERVABLE)
|
|
64
|
+
const observableRefAnnotation = createObservableAnnotation(OBSERVABLE_REF, {
|
|
65
65
|
enhancer: referenceEnhancer
|
|
66
66
|
})
|
|
67
|
-
const observableShallowAnnotation = createObservableAnnotation(
|
|
67
|
+
const observableShallowAnnotation = createObservableAnnotation(OBSERVABLE_SHALLOW, {
|
|
68
68
|
enhancer: shallowEnhancer
|
|
69
69
|
})
|
|
70
|
-
const observableStructAnnotation = createObservableAnnotation(
|
|
70
|
+
const observableStructAnnotation = createObservableAnnotation(OBSERVABLE_STRUCT, {
|
|
71
71
|
enhancer: refStructEnhancer
|
|
72
72
|
})
|
|
73
73
|
const observableDecoratorAnnotation = createDecoratorAnnotation(observableAnnotation)
|
package/src/api/when.ts
CHANGED
|
@@ -33,10 +33,10 @@ export function when(predicate: any, arg1?: any, arg2?: any): any {
|
|
|
33
33
|
function _when(predicate: () => boolean, effect: Lambda, opts: IWhenOptions): IReactionDisposer {
|
|
34
34
|
let timeoutHandle: any
|
|
35
35
|
if (typeof opts.timeout === "number") {
|
|
36
|
+
const error = new Error("WHEN_TIMEOUT")
|
|
36
37
|
timeoutHandle = setTimeout(() => {
|
|
37
38
|
if (!disposer[$mobx].isDisposed_) {
|
|
38
39
|
disposer()
|
|
39
|
-
const error = new Error("WHEN_TIMEOUT")
|
|
40
40
|
if (opts.onError) opts.onError(error)
|
|
41
41
|
else throw error
|
|
42
42
|
}
|
|
@@ -255,6 +255,11 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, IDeriva
|
|
|
255
255
|
if (!this.keepAlive_) {
|
|
256
256
|
clearObserving(this)
|
|
257
257
|
this.value_ = undefined // don't hold on to computed value!
|
|
258
|
+
if (__DEV__ && this.isTracing_ !== TraceMode.NONE) {
|
|
259
|
+
console.log(
|
|
260
|
+
`[mobx.trace] Computed value '${this.name_}' was suspended and it will recompute on the next access.`
|
|
261
|
+
)
|
|
262
|
+
}
|
|
258
263
|
}
|
|
259
264
|
}
|
|
260
265
|
|
|
@@ -283,17 +288,14 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, IDeriva
|
|
|
283
288
|
|
|
284
289
|
warnAboutUntrackedRead_() {
|
|
285
290
|
if (!__DEV__) return
|
|
286
|
-
if (this.requiresReaction_ === true) {
|
|
287
|
-
die(`[mobx] Computed value ${this.name_} is read outside a reactive context`)
|
|
288
|
-
}
|
|
289
291
|
if (this.isTracing_ !== TraceMode.NONE) {
|
|
290
292
|
console.log(
|
|
291
|
-
`[mobx.trace] '${this.name_}' is being read outside a reactive context. Doing a full recompute
|
|
293
|
+
`[mobx.trace] Computed value '${this.name_}' is being read outside a reactive context. Doing a full recompute.`
|
|
292
294
|
)
|
|
293
295
|
}
|
|
294
|
-
if (globalState.computedRequiresReaction) {
|
|
296
|
+
if (globalState.computedRequiresReaction || this.requiresReaction_) {
|
|
295
297
|
console.warn(
|
|
296
|
-
`[mobx] Computed value ${this.name_} is being read outside a reactive context. Doing a full recompute
|
|
298
|
+
`[mobx] Computed value '${this.name_}' is being read outside a reactive context. Doing a full recompute.`
|
|
297
299
|
)
|
|
298
300
|
}
|
|
299
301
|
}
|
package/src/core/derivation.ts
CHANGED
|
@@ -149,7 +149,9 @@ export function checkIfStateModificationsAreAllowed(atom: IAtom) {
|
|
|
149
149
|
|
|
150
150
|
export function checkIfStateReadsAreAllowed(observable: IObservable) {
|
|
151
151
|
if (__DEV__ && !globalState.allowStateReads && globalState.observableRequiresReaction) {
|
|
152
|
-
console.warn(
|
|
152
|
+
console.warn(
|
|
153
|
+
`[mobx] Observable '${observable.name_}' being read outside a reactive context.`
|
|
154
|
+
)
|
|
153
155
|
}
|
|
154
156
|
}
|
|
155
157
|
|
|
@@ -195,7 +197,7 @@ function warnAboutDerivationWithoutDependencies(derivation: IDerivation) {
|
|
|
195
197
|
|
|
196
198
|
if (globalState.reactionRequiresObservable || derivation.requiresObservable_) {
|
|
197
199
|
console.warn(
|
|
198
|
-
`[mobx] Derivation ${derivation.name_} is created/updated without reading any observable value
|
|
200
|
+
`[mobx] Derivation '${derivation.name_}' is created/updated without reading any observable value.`
|
|
199
201
|
)
|
|
200
202
|
}
|
|
201
203
|
}
|
package/src/mobx.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { die } from "./errors"
|
|
19
19
|
import { getGlobal } from "./utils/global"
|
|
20
|
-
;["Symbol", "Map", "Set"
|
|
20
|
+
;["Symbol", "Map", "Set"].forEach(m => {
|
|
21
21
|
let g = getGlobal()
|
|
22
22
|
if (typeof g[m] === "undefined") {
|
|
23
23
|
die(`MobX requires global '${m}' to be available or polyfilled`)
|
package/src/utils/comparer.ts
CHANGED
|
@@ -17,7 +17,11 @@ function shallowComparer(a: any, b: any): boolean {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function defaultComparer(a: any, b: any): boolean {
|
|
20
|
-
return Object.is(a, b)
|
|
20
|
+
if (Object.is) return Object.is(a, b)
|
|
21
|
+
|
|
22
|
+
return a === b
|
|
23
|
+
? a !== 0 || 1 / a === 1 / b
|
|
24
|
+
: a !== a && b !== b
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
export const comparer = {
|