mobx 6.12.0 → 6.12.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 +16 -0
- package/dist/core/reaction.d.ts +2 -2
- package/dist/mobx.cjs.development.js +9 -8
- 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 +9 -8
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +9 -8
- 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 +9 -8
- 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/dist/types/observableobject.d.ts +3 -3
- package/package.json +1 -1
- package/src/api/autorun.ts +2 -3
- package/src/core/derivation.ts +6 -3
- package/src/core/reaction.ts +3 -2
- package/src/types/legacyobservablearray.ts +1 -1
- package/src/types/observablearray.ts +2 -2
- package/src/types/observableobject.ts +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateObservableOptions, Annotation, ComputedValue, IAtom, IComputedValueOptions, IEnhancer, IInterceptable, IListenable, Lambda, ObservableValue } from "../internal";
|
|
1
|
+
import { CreateObservableOptions, $mobx, Annotation, ComputedValue, IAtom, IComputedValueOptions, IEnhancer, IInterceptable, IListenable, Lambda, ObservableValue } from "../internal";
|
|
2
2
|
export type IObjectDidChange<T = any> = {
|
|
3
3
|
observableKind: "object";
|
|
4
4
|
name: PropertyKey;
|
|
@@ -87,11 +87,11 @@ export declare class ObservableObjectAdministration implements IInterceptable<IO
|
|
|
87
87
|
observe_(callback: (changes: IObjectDidChange) => void, fireImmediately?: boolean): Lambda;
|
|
88
88
|
intercept_(handler: any): Lambda;
|
|
89
89
|
notifyPropertyAddition_(key: PropertyKey, value: any): void;
|
|
90
|
-
ownKeys_():
|
|
90
|
+
ownKeys_(): Array<string | symbol>;
|
|
91
91
|
keys_(): PropertyKey[];
|
|
92
92
|
}
|
|
93
93
|
export interface IIsObservableObject {
|
|
94
|
-
$mobx: ObservableObjectAdministration;
|
|
94
|
+
[$mobx]: ObservableObjectAdministration;
|
|
95
95
|
}
|
|
96
96
|
export declare function asObservableObject(target: any, options?: CreateObservableOptions): IIsObservableObject;
|
|
97
97
|
export declare function isObservableObject(thing: any): boolean;
|
package/package.json
CHANGED
package/src/api/autorun.ts
CHANGED
|
@@ -139,7 +139,6 @@ export function reaction<T, FireImmediately extends boolean = false>(
|
|
|
139
139
|
let firstTime = true
|
|
140
140
|
let isScheduled = false
|
|
141
141
|
let value: T
|
|
142
|
-
let oldValue: T | undefined
|
|
143
142
|
|
|
144
143
|
const equals: IEqualsComparer<T> = (opts as any).compareStructural
|
|
145
144
|
? comparer.structural
|
|
@@ -165,14 +164,14 @@ export function reaction<T, FireImmediately extends boolean = false>(
|
|
|
165
164
|
return
|
|
166
165
|
}
|
|
167
166
|
let changed: boolean = false
|
|
167
|
+
const oldValue = value
|
|
168
168
|
r.track(() => {
|
|
169
169
|
const nextValue = allowStateChanges(false, () => expression(r))
|
|
170
170
|
changed = firstTime || !equals(value, nextValue)
|
|
171
|
-
oldValue = value
|
|
172
171
|
value = nextValue
|
|
173
172
|
})
|
|
174
173
|
|
|
175
|
-
// This casting is nesessary as TS cannot infer proper type in current
|
|
174
|
+
// This casting is nesessary as TS cannot infer proper type in current function implementation
|
|
176
175
|
type OldValue = FireImmediately extends true ? T | undefined : T
|
|
177
176
|
if (firstTime && opts.fireImmediately!) {
|
|
178
177
|
effectAction(value, oldValue as OldValue, r)
|
package/src/core/derivation.ts
CHANGED
|
@@ -166,10 +166,13 @@ export function checkIfStateReadsAreAllowed(observable: IObservable) {
|
|
|
166
166
|
*/
|
|
167
167
|
export function trackDerivedFunction<T>(derivation: IDerivation, f: () => T, context: any) {
|
|
168
168
|
const prevAllowStateReads = allowStateReadsStart(true)
|
|
169
|
-
// pre allocate array allocation + room for variation in deps
|
|
170
|
-
// array will be trimmed by bindDependencies
|
|
171
169
|
changeDependenciesStateTo0(derivation)
|
|
172
|
-
|
|
170
|
+
// Preallocate array; will be trimmed by bindDependencies.
|
|
171
|
+
derivation.newObserving_ = new Array(
|
|
172
|
+
// Reserve constant space for initial dependencies, dynamic space otherwise.
|
|
173
|
+
// See https://github.com/mobxjs/mobx/pull/3833
|
|
174
|
+
derivation.runId_ === 0 ? 100 : derivation.observing_.length
|
|
175
|
+
)
|
|
173
176
|
derivation.unboundDepsCount_ = 0
|
|
174
177
|
derivation.runId_ = ++globalState.runId
|
|
175
178
|
const prevTracking = globalState.trackingDerivation
|
package/src/core/reaction.ts
CHANGED
|
@@ -18,7 +18,8 @@ import {
|
|
|
18
18
|
spyReportStart,
|
|
19
19
|
startBatch,
|
|
20
20
|
trace,
|
|
21
|
-
trackDerivedFunction,
|
|
21
|
+
trackDerivedFunction,
|
|
22
|
+
GenericAbortSignal
|
|
22
23
|
} from "../internal"
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -47,7 +48,7 @@ export interface IReactionPublic {
|
|
|
47
48
|
|
|
48
49
|
export interface IReactionDisposer {
|
|
49
50
|
(): void
|
|
50
|
-
$mobx: Reaction
|
|
51
|
+
[$mobx]: Reaction
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
export class Reaction implements IDerivation, IReactionPublic {
|
|
@@ -71,7 +71,7 @@ export class LegacyObservableArray<T> extends StubArray {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
if (safariPrototypeSetterInheritanceBug) {
|
|
74
|
-
// Seems that Safari won't use numeric prototype setter
|
|
74
|
+
// Seems that Safari won't use numeric prototype setter until any * numeric property is
|
|
75
75
|
// defined on the instance. After that it works fine, even if this property is deleted.
|
|
76
76
|
Object.defineProperty(this, "0", ENTRY_0)
|
|
77
77
|
}
|
|
@@ -563,7 +563,7 @@ function simpleFunc(funcName) {
|
|
|
563
563
|
}
|
|
564
564
|
}
|
|
565
565
|
|
|
566
|
-
// Make sure callbacks
|
|
566
|
+
// Make sure callbacks receive correct array arg #2326
|
|
567
567
|
function mapLikeFunc(funcName) {
|
|
568
568
|
return function (callback, thisArg) {
|
|
569
569
|
const adm: ObservableArrayAdministration = this[$mobx]
|
|
@@ -575,7 +575,7 @@ function mapLikeFunc(funcName) {
|
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
577
|
|
|
578
|
-
// Make sure callbacks
|
|
578
|
+
// Make sure callbacks receive correct array arg #2326
|
|
579
579
|
function reduceLikeFunc(funcName) {
|
|
580
580
|
return function () {
|
|
581
581
|
const adm: ObservableArrayAdministration = this[$mobx]
|
|
@@ -629,7 +629,7 @@ export class ObservableObjectAdministration
|
|
|
629
629
|
this.keysAtom_.reportChanged()
|
|
630
630
|
}
|
|
631
631
|
|
|
632
|
-
ownKeys_():
|
|
632
|
+
ownKeys_(): Array<string | symbol> {
|
|
633
633
|
this.keysAtom_.reportObserved()
|
|
634
634
|
return ownKeys(this.target_)
|
|
635
635
|
}
|
|
@@ -647,7 +647,7 @@ export class ObservableObjectAdministration
|
|
|
647
647
|
}
|
|
648
648
|
|
|
649
649
|
export interface IIsObservableObject {
|
|
650
|
-
$mobx: ObservableObjectAdministration
|
|
650
|
+
[$mobx]: ObservableObjectAdministration
|
|
651
651
|
}
|
|
652
652
|
|
|
653
653
|
export function asObservableObject(
|