mobx 6.10.2 → 6.11.0
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 +9 -0
- package/README.md +2 -2
- package/dist/api/action.d.ts +16 -15
- package/dist/api/annotation.d.ts +19 -18
- package/dist/api/autorun.d.ts +25 -25
- package/dist/api/become-observed.d.ts +5 -5
- package/dist/api/computed.d.ts +14 -13
- package/dist/api/configure.d.ts +17 -17
- package/dist/api/decorators.d.ts +20 -17
- package/dist/api/extendobservable.d.ts +2 -2
- package/dist/api/extras.d.ts +10 -10
- package/dist/api/flow.d.ts +19 -18
- package/dist/api/intercept-read.d.ts +8 -8
- package/dist/api/intercept.d.ts +8 -8
- package/dist/api/iscomputed.d.ts +3 -3
- package/dist/api/isobservable.d.ts +2 -2
- package/dist/api/makeObservable.d.ts +6 -6
- package/dist/api/object-api.d.ts +36 -36
- package/dist/api/observable.d.ts +45 -44
- package/dist/api/observe.d.ts +8 -8
- package/dist/api/tojs.d.ts +7 -7
- package/dist/api/trace.d.ts +3 -3
- package/dist/api/transaction.d.ts +8 -8
- package/dist/api/when.d.ts +11 -11
- package/dist/core/action.d.ts +20 -20
- package/dist/core/atom.d.ts +37 -37
- package/dist/core/computedvalue.d.ts +99 -99
- package/dist/core/derivation.d.ts +73 -73
- package/dist/core/globalstate.d.ts +121 -121
- package/dist/core/observable.d.ts +45 -45
- package/dist/core/reaction.d.ts +62 -62
- package/dist/core/spy.d.ts +37 -37
- package/dist/errors.d.ts +42 -42
- package/dist/internal.d.ts +54 -54
- package/dist/mobx.cjs.development.js +419 -252
- 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.d.ts +2 -2
- package/dist/mobx.esm.development.js +419 -252
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +419 -252
- 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 +419 -252
- 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/actionannotation.d.ts +8 -8
- package/dist/types/autoannotation.d.ts +3 -3
- package/dist/types/computedannotation.d.ts +2 -2
- package/dist/types/decorator_fills.d.ts +6 -0
- package/dist/types/dynamicobject.d.ts +2 -2
- package/dist/types/flowannotation.d.ts +2 -2
- package/dist/types/generic-abort-signal.d.ts +6 -6
- package/dist/types/intercept-utils.d.ts +8 -8
- package/dist/types/legacyobservablearray.d.ts +14 -3
- package/dist/types/listen-utils.d.ts +7 -7
- package/dist/types/modifiers.d.ts +7 -7
- package/dist/types/observableannotation.d.ts +2 -2
- package/dist/types/observablearray.d.ts +85 -85
- package/dist/types/observablemap.d.ts +78 -78
- package/dist/types/observableobject.d.ts +98 -98
- package/dist/types/observableset.d.ts +53 -53
- package/dist/types/observablevalue.d.ts +49 -49
- package/dist/types/overrideannotation.d.ts +4 -3
- package/dist/types/type-utils.d.ts +11 -11
- package/dist/utils/comparer.d.ts +14 -14
- package/dist/utils/eq.d.ts +1 -1
- package/dist/utils/global.d.ts +1 -1
- package/dist/utils/iterable.d.ts +1 -1
- package/dist/utils/utils.d.ts +45 -45
- package/package.json +1 -1
- package/src/api/action.ts +21 -4
- package/src/api/annotation.ts +1 -0
- package/src/api/computed.ts +11 -4
- package/src/api/decorators.ts +33 -8
- package/src/api/flow.ts +10 -3
- package/src/api/observable.ts +20 -6
- package/src/types/actionannotation.ts +48 -2
- package/src/types/autoannotation.ts +8 -2
- package/src/types/computedannotation.ts +39 -2
- package/src/types/decorator_fills.ts +33 -0
- package/src/types/flowannotation.ts +28 -2
- package/src/types/legacyobservablearray.ts +1 -1
- package/src/types/observableannotation.ts +75 -2
- package/src/types/overrideannotation.ts +15 -7
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
import { IDerivation, IObservable, Reaction } from "../internal";
|
|
2
|
-
import { ComputedValue } from "./computedvalue";
|
|
3
|
-
export
|
|
4
|
-
export declare class MobXGlobals {
|
|
5
|
-
/**
|
|
6
|
-
* MobXGlobals version.
|
|
7
|
-
* MobX compatiblity with other versions loaded in memory as long as this version matches.
|
|
8
|
-
* It indicates that the global state still stores similar information
|
|
9
|
-
*
|
|
10
|
-
* N.B: this version is unrelated to the package version of MobX, and is only the version of the
|
|
11
|
-
* internal state storage of MobX, and can be the same across many different package versions
|
|
12
|
-
*/
|
|
13
|
-
version: number;
|
|
14
|
-
/**
|
|
15
|
-
* globally unique token to signal unchanged
|
|
16
|
-
*/
|
|
17
|
-
UNCHANGED: IUNCHANGED;
|
|
18
|
-
/**
|
|
19
|
-
* Currently running derivation
|
|
20
|
-
*/
|
|
21
|
-
trackingDerivation: IDerivation | null;
|
|
22
|
-
/**
|
|
23
|
-
* Currently running reaction. This determines if we currently have a reactive context.
|
|
24
|
-
* (Tracking derivation is also set for temporal tracking of computed values inside actions,
|
|
25
|
-
* but trackingReaction can only be set by a form of Reaction)
|
|
26
|
-
*/
|
|
27
|
-
trackingContext: Reaction | ComputedValue<any> | null;
|
|
28
|
-
/**
|
|
29
|
-
* Each time a derivation is tracked, it is assigned a unique run-id
|
|
30
|
-
*/
|
|
31
|
-
runId: number;
|
|
32
|
-
/**
|
|
33
|
-
* 'guid' for general purpose. Will be persisted amongst resets.
|
|
34
|
-
*/
|
|
35
|
-
mobxGuid: number;
|
|
36
|
-
/**
|
|
37
|
-
* Are we in a batch block? (and how many of them)
|
|
38
|
-
*/
|
|
39
|
-
inBatch: number;
|
|
40
|
-
/**
|
|
41
|
-
* ID of the latest batch. Used to suppress reportChanged of newly created atoms.
|
|
42
|
-
* Note the value persists even after batch ended.
|
|
43
|
-
*/
|
|
44
|
-
batchId: number;
|
|
45
|
-
/**
|
|
46
|
-
* Observables that don't have observers anymore, and are about to be
|
|
47
|
-
* suspended, unless somebody else accesses it in the same batch
|
|
48
|
-
*
|
|
49
|
-
* @type {IObservable[]}
|
|
50
|
-
*/
|
|
51
|
-
pendingUnobservations: IObservable[];
|
|
52
|
-
/**
|
|
53
|
-
* List of scheduled, not yet executed, reactions.
|
|
54
|
-
*/
|
|
55
|
-
pendingReactions: Reaction[];
|
|
56
|
-
/**
|
|
57
|
-
* Are we currently processing reactions?
|
|
58
|
-
*/
|
|
59
|
-
isRunningReactions: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Is it allowed to change observables at this point?
|
|
62
|
-
* In general, MobX doesn't allow that when running computations and React.render.
|
|
63
|
-
* To ensure that those functions stay pure.
|
|
64
|
-
*/
|
|
65
|
-
allowStateChanges: boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Is it allowed to read observables at this point?
|
|
68
|
-
* Used to hold the state needed for `observableRequiresReaction`
|
|
69
|
-
*/
|
|
70
|
-
allowStateReads: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* If strict mode is enabled, state changes are by default not allowed
|
|
73
|
-
*/
|
|
74
|
-
enforceActions: boolean | "always";
|
|
75
|
-
/**
|
|
76
|
-
* Spy callbacks
|
|
77
|
-
*/
|
|
78
|
-
spyListeners: {
|
|
79
|
-
(change: any): void;
|
|
80
|
-
}[];
|
|
81
|
-
/**
|
|
82
|
-
* Globally attached error handlers that react specifically to errors in reactions
|
|
83
|
-
*/
|
|
84
|
-
globalReactionErrorHandlers: ((error: any, derivation: IDerivation) => void)[];
|
|
85
|
-
/**
|
|
86
|
-
* Warn if computed values are accessed outside a reactive context
|
|
87
|
-
*/
|
|
88
|
-
computedRequiresReaction: boolean;
|
|
89
|
-
/**
|
|
90
|
-
* (Experimental)
|
|
91
|
-
* Warn if you try to create to derivation / reactive context without accessing any observable.
|
|
92
|
-
*/
|
|
93
|
-
reactionRequiresObservable: boolean;
|
|
94
|
-
/**
|
|
95
|
-
* (Experimental)
|
|
96
|
-
* Warn if observables are accessed outside a reactive context
|
|
97
|
-
*/
|
|
98
|
-
observableRequiresReaction: boolean;
|
|
99
|
-
disableErrorBoundaries: boolean;
|
|
100
|
-
suppressReactionErrors: boolean;
|
|
101
|
-
useProxies: boolean;
|
|
102
|
-
verifyProxies: boolean;
|
|
103
|
-
/**
|
|
104
|
-
* False forces all object's descriptors to
|
|
105
|
-
* writable: true
|
|
106
|
-
* configurable: true
|
|
107
|
-
*/
|
|
108
|
-
safeDescriptors: boolean;
|
|
109
|
-
/**
|
|
110
|
-
* Changes with each state update, used by useSyncExternalStore
|
|
111
|
-
*/
|
|
112
|
-
stateVersion: number;
|
|
113
|
-
}
|
|
114
|
-
export declare let globalState: MobXGlobals;
|
|
115
|
-
export declare function isolateGlobalState(): void;
|
|
116
|
-
export declare function getGlobalState(): any;
|
|
117
|
-
/**
|
|
118
|
-
* For testing purposes only; this will break the internal state of existing observables,
|
|
119
|
-
* but can be used to get back at a stable state after throwing errors
|
|
120
|
-
*/
|
|
121
|
-
export declare function resetGlobalState(): void;
|
|
1
|
+
import { IDerivation, IObservable, Reaction } from "../internal";
|
|
2
|
+
import { ComputedValue } from "./computedvalue";
|
|
3
|
+
export type IUNCHANGED = {};
|
|
4
|
+
export declare class MobXGlobals {
|
|
5
|
+
/**
|
|
6
|
+
* MobXGlobals version.
|
|
7
|
+
* MobX compatiblity with other versions loaded in memory as long as this version matches.
|
|
8
|
+
* It indicates that the global state still stores similar information
|
|
9
|
+
*
|
|
10
|
+
* N.B: this version is unrelated to the package version of MobX, and is only the version of the
|
|
11
|
+
* internal state storage of MobX, and can be the same across many different package versions
|
|
12
|
+
*/
|
|
13
|
+
version: number;
|
|
14
|
+
/**
|
|
15
|
+
* globally unique token to signal unchanged
|
|
16
|
+
*/
|
|
17
|
+
UNCHANGED: IUNCHANGED;
|
|
18
|
+
/**
|
|
19
|
+
* Currently running derivation
|
|
20
|
+
*/
|
|
21
|
+
trackingDerivation: IDerivation | null;
|
|
22
|
+
/**
|
|
23
|
+
* Currently running reaction. This determines if we currently have a reactive context.
|
|
24
|
+
* (Tracking derivation is also set for temporal tracking of computed values inside actions,
|
|
25
|
+
* but trackingReaction can only be set by a form of Reaction)
|
|
26
|
+
*/
|
|
27
|
+
trackingContext: Reaction | ComputedValue<any> | null;
|
|
28
|
+
/**
|
|
29
|
+
* Each time a derivation is tracked, it is assigned a unique run-id
|
|
30
|
+
*/
|
|
31
|
+
runId: number;
|
|
32
|
+
/**
|
|
33
|
+
* 'guid' for general purpose. Will be persisted amongst resets.
|
|
34
|
+
*/
|
|
35
|
+
mobxGuid: number;
|
|
36
|
+
/**
|
|
37
|
+
* Are we in a batch block? (and how many of them)
|
|
38
|
+
*/
|
|
39
|
+
inBatch: number;
|
|
40
|
+
/**
|
|
41
|
+
* ID of the latest batch. Used to suppress reportChanged of newly created atoms.
|
|
42
|
+
* Note the value persists even after batch ended.
|
|
43
|
+
*/
|
|
44
|
+
batchId: number;
|
|
45
|
+
/**
|
|
46
|
+
* Observables that don't have observers anymore, and are about to be
|
|
47
|
+
* suspended, unless somebody else accesses it in the same batch
|
|
48
|
+
*
|
|
49
|
+
* @type {IObservable[]}
|
|
50
|
+
*/
|
|
51
|
+
pendingUnobservations: IObservable[];
|
|
52
|
+
/**
|
|
53
|
+
* List of scheduled, not yet executed, reactions.
|
|
54
|
+
*/
|
|
55
|
+
pendingReactions: Reaction[];
|
|
56
|
+
/**
|
|
57
|
+
* Are we currently processing reactions?
|
|
58
|
+
*/
|
|
59
|
+
isRunningReactions: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Is it allowed to change observables at this point?
|
|
62
|
+
* In general, MobX doesn't allow that when running computations and React.render.
|
|
63
|
+
* To ensure that those functions stay pure.
|
|
64
|
+
*/
|
|
65
|
+
allowStateChanges: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Is it allowed to read observables at this point?
|
|
68
|
+
* Used to hold the state needed for `observableRequiresReaction`
|
|
69
|
+
*/
|
|
70
|
+
allowStateReads: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* If strict mode is enabled, state changes are by default not allowed
|
|
73
|
+
*/
|
|
74
|
+
enforceActions: boolean | "always";
|
|
75
|
+
/**
|
|
76
|
+
* Spy callbacks
|
|
77
|
+
*/
|
|
78
|
+
spyListeners: {
|
|
79
|
+
(change: any): void;
|
|
80
|
+
}[];
|
|
81
|
+
/**
|
|
82
|
+
* Globally attached error handlers that react specifically to errors in reactions
|
|
83
|
+
*/
|
|
84
|
+
globalReactionErrorHandlers: ((error: any, derivation: IDerivation) => void)[];
|
|
85
|
+
/**
|
|
86
|
+
* Warn if computed values are accessed outside a reactive context
|
|
87
|
+
*/
|
|
88
|
+
computedRequiresReaction: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* (Experimental)
|
|
91
|
+
* Warn if you try to create to derivation / reactive context without accessing any observable.
|
|
92
|
+
*/
|
|
93
|
+
reactionRequiresObservable: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* (Experimental)
|
|
96
|
+
* Warn if observables are accessed outside a reactive context
|
|
97
|
+
*/
|
|
98
|
+
observableRequiresReaction: boolean;
|
|
99
|
+
disableErrorBoundaries: boolean;
|
|
100
|
+
suppressReactionErrors: boolean;
|
|
101
|
+
useProxies: boolean;
|
|
102
|
+
verifyProxies: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* False forces all object's descriptors to
|
|
105
|
+
* writable: true
|
|
106
|
+
* configurable: true
|
|
107
|
+
*/
|
|
108
|
+
safeDescriptors: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Changes with each state update, used by useSyncExternalStore
|
|
111
|
+
*/
|
|
112
|
+
stateVersion: number;
|
|
113
|
+
}
|
|
114
|
+
export declare let globalState: MobXGlobals;
|
|
115
|
+
export declare function isolateGlobalState(): void;
|
|
116
|
+
export declare function getGlobalState(): any;
|
|
117
|
+
/**
|
|
118
|
+
* For testing purposes only; this will break the internal state of existing observables,
|
|
119
|
+
* but can be used to get back at a stable state after throwing errors
|
|
120
|
+
*/
|
|
121
|
+
export declare function resetGlobalState(): void;
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { Lambda, IDerivation, IDerivationState_ } from "../internal";
|
|
2
|
-
export interface IDepTreeNode {
|
|
3
|
-
name_: string;
|
|
4
|
-
observing_?: IObservable[];
|
|
5
|
-
}
|
|
6
|
-
export interface IObservable extends IDepTreeNode {
|
|
7
|
-
diffValue_: number;
|
|
8
|
-
/**
|
|
9
|
-
* Id of the derivation *run* that last accessed this observable.
|
|
10
|
-
* If this id equals the *run* id of the current derivation,
|
|
11
|
-
* the dependency is already established
|
|
12
|
-
*/
|
|
13
|
-
lastAccessedBy_: number;
|
|
14
|
-
isBeingObserved_: boolean;
|
|
15
|
-
lowestObserverState_: IDerivationState_;
|
|
16
|
-
isPendingUnobservation_: boolean;
|
|
17
|
-
observers_: Set<IDerivation>;
|
|
18
|
-
onBUO(): void;
|
|
19
|
-
onBO(): void;
|
|
20
|
-
onBUOL: Set<Lambda> | undefined;
|
|
21
|
-
onBOL: Set<Lambda> | undefined;
|
|
22
|
-
}
|
|
23
|
-
export declare function hasObservers(observable: IObservable): boolean;
|
|
24
|
-
export declare function getObservers(observable: IObservable): Set<IDerivation>;
|
|
25
|
-
export declare function addObserver(observable: IObservable, node: IDerivation): void;
|
|
26
|
-
export declare function removeObserver(observable: IObservable, node: IDerivation): void;
|
|
27
|
-
export declare function queueForUnobservation(observable: IObservable): void;
|
|
28
|
-
/**
|
|
29
|
-
* Batch starts a transaction, at least for purposes of memoizing ComputedValues when nothing else does.
|
|
30
|
-
* During a batch `onBecomeUnobserved` will be called at most once per observable.
|
|
31
|
-
* Avoids unnecessary recalculations.
|
|
32
|
-
*/
|
|
33
|
-
export declare function startBatch(): void;
|
|
34
|
-
export declare function endBatch(): void;
|
|
35
|
-
export declare function reportObserved(observable: IObservable): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* NOTE: current propagation mechanism will in case of self reruning autoruns behave unexpectedly
|
|
38
|
-
* It will propagate changes to observers from previous run
|
|
39
|
-
* It's hard or maybe impossible (with reasonable perf) to get it right with current approach
|
|
40
|
-
* Hopefully self reruning autoruns aren't a feature people should depend on
|
|
41
|
-
* Also most basic use cases should be ok
|
|
42
|
-
*/
|
|
43
|
-
export declare function propagateChanged(observable: IObservable): void;
|
|
44
|
-
export declare function propagateChangeConfirmed(observable: IObservable): void;
|
|
45
|
-
export declare function propagateMaybeChanged(observable: IObservable): void;
|
|
1
|
+
import { Lambda, IDerivation, IDerivationState_ } from "../internal";
|
|
2
|
+
export interface IDepTreeNode {
|
|
3
|
+
name_: string;
|
|
4
|
+
observing_?: IObservable[];
|
|
5
|
+
}
|
|
6
|
+
export interface IObservable extends IDepTreeNode {
|
|
7
|
+
diffValue_: number;
|
|
8
|
+
/**
|
|
9
|
+
* Id of the derivation *run* that last accessed this observable.
|
|
10
|
+
* If this id equals the *run* id of the current derivation,
|
|
11
|
+
* the dependency is already established
|
|
12
|
+
*/
|
|
13
|
+
lastAccessedBy_: number;
|
|
14
|
+
isBeingObserved_: boolean;
|
|
15
|
+
lowestObserverState_: IDerivationState_;
|
|
16
|
+
isPendingUnobservation_: boolean;
|
|
17
|
+
observers_: Set<IDerivation>;
|
|
18
|
+
onBUO(): void;
|
|
19
|
+
onBO(): void;
|
|
20
|
+
onBUOL: Set<Lambda> | undefined;
|
|
21
|
+
onBOL: Set<Lambda> | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare function hasObservers(observable: IObservable): boolean;
|
|
24
|
+
export declare function getObservers(observable: IObservable): Set<IDerivation>;
|
|
25
|
+
export declare function addObserver(observable: IObservable, node: IDerivation): void;
|
|
26
|
+
export declare function removeObserver(observable: IObservable, node: IDerivation): void;
|
|
27
|
+
export declare function queueForUnobservation(observable: IObservable): void;
|
|
28
|
+
/**
|
|
29
|
+
* Batch starts a transaction, at least for purposes of memoizing ComputedValues when nothing else does.
|
|
30
|
+
* During a batch `onBecomeUnobserved` will be called at most once per observable.
|
|
31
|
+
* Avoids unnecessary recalculations.
|
|
32
|
+
*/
|
|
33
|
+
export declare function startBatch(): void;
|
|
34
|
+
export declare function endBatch(): void;
|
|
35
|
+
export declare function reportObserved(observable: IObservable): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* NOTE: current propagation mechanism will in case of self reruning autoruns behave unexpectedly
|
|
38
|
+
* It will propagate changes to observers from previous run
|
|
39
|
+
* It's hard or maybe impossible (with reasonable perf) to get it right with current approach
|
|
40
|
+
* Hopefully self reruning autoruns aren't a feature people should depend on
|
|
41
|
+
* Also most basic use cases should be ok
|
|
42
|
+
*/
|
|
43
|
+
export declare function propagateChanged(observable: IObservable): void;
|
|
44
|
+
export declare function propagateChangeConfirmed(observable: IObservable): void;
|
|
45
|
+
export declare function propagateMaybeChanged(observable: IObservable): void;
|
package/dist/core/reaction.d.ts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { IDerivation, IDerivationState_, IObservable, Lambda, TraceMode, GenericAbortSignal } from "../internal";
|
|
2
|
-
/**
|
|
3
|
-
* Reactions are a special kind of derivations. Several things distinguishes them from normal reactive computations
|
|
4
|
-
*
|
|
5
|
-
* 1) They will always run, whether they are used by other computations or not.
|
|
6
|
-
* This means that they are very suitable for triggering side effects like logging, updating the DOM and making network requests.
|
|
7
|
-
* 2) They are not observable themselves
|
|
8
|
-
* 3) They will always run after any 'normal' derivations
|
|
9
|
-
* 4) They are allowed to change the state and thereby triggering themselves again, as long as they make sure the state propagates to a stable state in a reasonable amount of iterations.
|
|
10
|
-
*
|
|
11
|
-
* The state machine of a Reaction is as follows:
|
|
12
|
-
*
|
|
13
|
-
* 1) after creating, the reaction should be started by calling `runReaction` or by scheduling it (see also `autorun`)
|
|
14
|
-
* 2) the `onInvalidate` handler should somehow result in a call to `this.track(someFunction)`
|
|
15
|
-
* 3) all observables accessed in `someFunction` will be observed by this reaction.
|
|
16
|
-
* 4) as soon as some of the dependencies has changed the Reaction will be rescheduled for another run (after the current mutation or transaction). `isScheduled` will yield true once a dependency is stale and during this period
|
|
17
|
-
* 5) `onInvalidate` will be called, and we are back at step 1.
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
export interface IReactionPublic {
|
|
21
|
-
dispose(): void;
|
|
22
|
-
trace(enterBreakPoint?: boolean): void;
|
|
23
|
-
}
|
|
24
|
-
export interface IReactionDisposer {
|
|
25
|
-
(): void;
|
|
26
|
-
$mobx: Reaction;
|
|
27
|
-
}
|
|
28
|
-
export declare class Reaction implements IDerivation, IReactionPublic {
|
|
29
|
-
name_: string;
|
|
30
|
-
private onInvalidate_;
|
|
31
|
-
private errorHandler_?;
|
|
32
|
-
requiresObservable_?: any;
|
|
33
|
-
observing_: IObservable[];
|
|
34
|
-
newObserving_: IObservable[];
|
|
35
|
-
dependenciesState_: IDerivationState_;
|
|
36
|
-
diffValue_: number;
|
|
37
|
-
runId_: number;
|
|
38
|
-
unboundDepsCount_: number;
|
|
39
|
-
isDisposed_: boolean;
|
|
40
|
-
isScheduled_: boolean;
|
|
41
|
-
isTrackPending_: boolean;
|
|
42
|
-
isRunning_: boolean;
|
|
43
|
-
isTracing_: TraceMode;
|
|
44
|
-
constructor(name_: string, onInvalidate_: () => void, errorHandler_?: ((error: any, derivation: IDerivation) => void) | undefined, requiresObservable_?: any);
|
|
45
|
-
onBecomeStale_(): void;
|
|
46
|
-
schedule_(): void;
|
|
47
|
-
isScheduled(): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* internal, use schedule() if you intend to kick off a reaction
|
|
50
|
-
*/
|
|
51
|
-
runReaction_(): void;
|
|
52
|
-
track(fn: () => void): void;
|
|
53
|
-
reportExceptionInDerivation_(error: any): void;
|
|
54
|
-
dispose(): void;
|
|
55
|
-
getDisposer_(abortSignal?: GenericAbortSignal): IReactionDisposer;
|
|
56
|
-
toString(): string;
|
|
57
|
-
trace(enterBreakPoint?: boolean): void;
|
|
58
|
-
}
|
|
59
|
-
export declare function onReactionError(handler: (error: any, derivation: IDerivation) => void): Lambda;
|
|
60
|
-
export declare function runReactions(): void;
|
|
61
|
-
export declare const isReaction: (x: any) => x is Reaction;
|
|
62
|
-
export declare function setReactionScheduler(fn: (f: () => void) => void): void;
|
|
1
|
+
import { IDerivation, IDerivationState_, IObservable, Lambda, TraceMode, GenericAbortSignal } from "../internal";
|
|
2
|
+
/**
|
|
3
|
+
* Reactions are a special kind of derivations. Several things distinguishes them from normal reactive computations
|
|
4
|
+
*
|
|
5
|
+
* 1) They will always run, whether they are used by other computations or not.
|
|
6
|
+
* This means that they are very suitable for triggering side effects like logging, updating the DOM and making network requests.
|
|
7
|
+
* 2) They are not observable themselves
|
|
8
|
+
* 3) They will always run after any 'normal' derivations
|
|
9
|
+
* 4) They are allowed to change the state and thereby triggering themselves again, as long as they make sure the state propagates to a stable state in a reasonable amount of iterations.
|
|
10
|
+
*
|
|
11
|
+
* The state machine of a Reaction is as follows:
|
|
12
|
+
*
|
|
13
|
+
* 1) after creating, the reaction should be started by calling `runReaction` or by scheduling it (see also `autorun`)
|
|
14
|
+
* 2) the `onInvalidate` handler should somehow result in a call to `this.track(someFunction)`
|
|
15
|
+
* 3) all observables accessed in `someFunction` will be observed by this reaction.
|
|
16
|
+
* 4) as soon as some of the dependencies has changed the Reaction will be rescheduled for another run (after the current mutation or transaction). `isScheduled` will yield true once a dependency is stale and during this period
|
|
17
|
+
* 5) `onInvalidate` will be called, and we are back at step 1.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export interface IReactionPublic {
|
|
21
|
+
dispose(): void;
|
|
22
|
+
trace(enterBreakPoint?: boolean): void;
|
|
23
|
+
}
|
|
24
|
+
export interface IReactionDisposer {
|
|
25
|
+
(): void;
|
|
26
|
+
$mobx: Reaction;
|
|
27
|
+
}
|
|
28
|
+
export declare class Reaction implements IDerivation, IReactionPublic {
|
|
29
|
+
name_: string;
|
|
30
|
+
private onInvalidate_;
|
|
31
|
+
private errorHandler_?;
|
|
32
|
+
requiresObservable_?: any;
|
|
33
|
+
observing_: IObservable[];
|
|
34
|
+
newObserving_: IObservable[];
|
|
35
|
+
dependenciesState_: IDerivationState_;
|
|
36
|
+
diffValue_: number;
|
|
37
|
+
runId_: number;
|
|
38
|
+
unboundDepsCount_: number;
|
|
39
|
+
isDisposed_: boolean;
|
|
40
|
+
isScheduled_: boolean;
|
|
41
|
+
isTrackPending_: boolean;
|
|
42
|
+
isRunning_: boolean;
|
|
43
|
+
isTracing_: TraceMode;
|
|
44
|
+
constructor(name_: string, onInvalidate_: () => void, errorHandler_?: ((error: any, derivation: IDerivation) => void) | undefined, requiresObservable_?: any);
|
|
45
|
+
onBecomeStale_(): void;
|
|
46
|
+
schedule_(): void;
|
|
47
|
+
isScheduled(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* internal, use schedule() if you intend to kick off a reaction
|
|
50
|
+
*/
|
|
51
|
+
runReaction_(): void;
|
|
52
|
+
track(fn: () => void): void;
|
|
53
|
+
reportExceptionInDerivation_(error: any): void;
|
|
54
|
+
dispose(): void;
|
|
55
|
+
getDisposer_(abortSignal?: GenericAbortSignal): IReactionDisposer;
|
|
56
|
+
toString(): string;
|
|
57
|
+
trace(enterBreakPoint?: boolean): void;
|
|
58
|
+
}
|
|
59
|
+
export declare function onReactionError(handler: (error: any, derivation: IDerivation) => void): Lambda;
|
|
60
|
+
export declare function runReactions(): void;
|
|
61
|
+
export declare const isReaction: (x: any) => x is Reaction;
|
|
62
|
+
export declare function setReactionScheduler(fn: (f: () => void) => void): void;
|
package/dist/core/spy.d.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { IComputedDidChange } from "./computedvalue";
|
|
2
|
-
import { IValueDidChange, IBoxDidChange } from "./../types/observablevalue";
|
|
3
|
-
import { IObjectDidChange } from "./../types/observableobject";
|
|
4
|
-
import { IArrayDidChange } from "./../types/observablearray";
|
|
5
|
-
import { Lambda, ISetDidChange, IMapDidChange } from "../internal";
|
|
6
|
-
export declare function isSpyEnabled(): boolean;
|
|
7
|
-
export
|
|
8
|
-
type: "action";
|
|
9
|
-
name: string;
|
|
10
|
-
object: unknown;
|
|
11
|
-
arguments: unknown[];
|
|
12
|
-
} | {
|
|
13
|
-
type: "scheduled-reaction";
|
|
14
|
-
name: string;
|
|
15
|
-
} | {
|
|
16
|
-
type: "reaction";
|
|
17
|
-
name: string;
|
|
18
|
-
} | {
|
|
19
|
-
type: "error";
|
|
20
|
-
name: string;
|
|
21
|
-
message: string;
|
|
22
|
-
error: string;
|
|
23
|
-
} | IComputedDidChange<unknown> | IObjectDidChange<unknown> | IArrayDidChange<unknown> | IMapDidChange<unknown, unknown> | ISetDidChange<unknown> | IValueDidChange<unknown> | IBoxDidChange<unknown> | {
|
|
24
|
-
type: "report-end";
|
|
25
|
-
spyReportEnd: true;
|
|
26
|
-
time?: number;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
spyReportStart?: true;
|
|
30
|
-
};
|
|
31
|
-
export declare function spyReport(event: SpyEvent): void;
|
|
32
|
-
export declare function spyReportStart(event: PureSpyEvent): void;
|
|
33
|
-
export declare function spyReportEnd(change?: {
|
|
34
|
-
time?: number;
|
|
35
|
-
}): void;
|
|
36
|
-
export declare function spy(listener: (change: SpyEvent) => void): Lambda;
|
|
37
|
-
export {};
|
|
1
|
+
import { IComputedDidChange } from "./computedvalue";
|
|
2
|
+
import { IValueDidChange, IBoxDidChange } from "./../types/observablevalue";
|
|
3
|
+
import { IObjectDidChange } from "./../types/observableobject";
|
|
4
|
+
import { IArrayDidChange } from "./../types/observablearray";
|
|
5
|
+
import { Lambda, ISetDidChange, IMapDidChange } from "../internal";
|
|
6
|
+
export declare function isSpyEnabled(): boolean;
|
|
7
|
+
export type PureSpyEvent = {
|
|
8
|
+
type: "action";
|
|
9
|
+
name: string;
|
|
10
|
+
object: unknown;
|
|
11
|
+
arguments: unknown[];
|
|
12
|
+
} | {
|
|
13
|
+
type: "scheduled-reaction";
|
|
14
|
+
name: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: "reaction";
|
|
17
|
+
name: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: "error";
|
|
20
|
+
name: string;
|
|
21
|
+
message: string;
|
|
22
|
+
error: string;
|
|
23
|
+
} | IComputedDidChange<unknown> | IObjectDidChange<unknown> | IArrayDidChange<unknown> | IMapDidChange<unknown, unknown> | ISetDidChange<unknown> | IValueDidChange<unknown> | IBoxDidChange<unknown> | {
|
|
24
|
+
type: "report-end";
|
|
25
|
+
spyReportEnd: true;
|
|
26
|
+
time?: number;
|
|
27
|
+
};
|
|
28
|
+
type SpyEvent = PureSpyEvent & {
|
|
29
|
+
spyReportStart?: true;
|
|
30
|
+
};
|
|
31
|
+
export declare function spyReport(event: SpyEvent): void;
|
|
32
|
+
export declare function spyReportStart(event: PureSpyEvent): void;
|
|
33
|
+
export declare function spyReportEnd(change?: {
|
|
34
|
+
time?: number;
|
|
35
|
+
}): void;
|
|
36
|
+
export declare function spy(listener: (change: SpyEvent) => void): Lambda;
|
|
37
|
+
export {};
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
declare const niceErrors: {
|
|
2
|
-
readonly 0: "Invalid value for configuration 'enforceActions', expected 'never', 'always' or 'observed'";
|
|
3
|
-
readonly 1: (annotationType: any, key: PropertyKey) => string;
|
|
4
|
-
readonly 5: "'keys()' can only be used on observable objects, arrays, sets and maps";
|
|
5
|
-
readonly 6: "'values()' can only be used on observable objects, arrays, sets and maps";
|
|
6
|
-
readonly 7: "'entries()' can only be used on observable objects, arrays and maps";
|
|
7
|
-
readonly 8: "'set()' can only be used on observable objects, arrays and maps";
|
|
8
|
-
readonly 9: "'remove()' can only be used on observable objects, arrays and maps";
|
|
9
|
-
readonly 10: "'has()' can only be used on observable objects, arrays and maps";
|
|
10
|
-
readonly 11: "'get()' can only be used on observable objects, arrays and maps";
|
|
11
|
-
readonly 12: "Invalid annotation";
|
|
12
|
-
readonly 13: "Dynamic observable objects cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)";
|
|
13
|
-
readonly 14: "Intercept handlers should return nothing or a change object";
|
|
14
|
-
readonly 15: "Observable arrays cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)";
|
|
15
|
-
readonly 16: "Modification exception: the internal structure of an observable array was changed.";
|
|
16
|
-
readonly 17: (index: any, length: any) => string;
|
|
17
|
-
readonly 18: "mobx.map requires Map polyfill for the current browser. Check babel-polyfill or core-js/es6/map.js";
|
|
18
|
-
readonly 19: (other: any) => string;
|
|
19
|
-
readonly 20: (other: any) => string;
|
|
20
|
-
readonly 21: (dataStructure: any) => string;
|
|
21
|
-
readonly 22: "mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js";
|
|
22
|
-
readonly 23: "It is not possible to get index atoms from arrays";
|
|
23
|
-
readonly 24: (thing: any) => string;
|
|
24
|
-
readonly 25: (property: any, name: any) => string;
|
|
25
|
-
readonly 26: "please specify a property";
|
|
26
|
-
readonly 27: (property: any, name: any) => string;
|
|
27
|
-
readonly 28: (thing: any) => string;
|
|
28
|
-
readonly 29: "Expecting some object";
|
|
29
|
-
readonly 30: "invalid action stack. did you forget to finish an action?";
|
|
30
|
-
readonly 31: "missing option for computed: get";
|
|
31
|
-
readonly 32: (name: any, derivation: any) => string;
|
|
32
|
-
readonly 33: (name: any) => string;
|
|
33
|
-
readonly 34: (name: any) => string;
|
|
34
|
-
readonly 35: "There are multiple, different versions of MobX active. Make sure MobX is loaded only once or use `configure({ isolateGlobalState: true })`";
|
|
35
|
-
readonly 36: "isolateGlobalState should be called before MobX is running any reactions";
|
|
36
|
-
readonly 37: (method: any) => string;
|
|
37
|
-
readonly 38: "'ownKeys()' can only be used on observable objects";
|
|
38
|
-
readonly 39: "'defineProperty()' can only be used on observable objects";
|
|
39
|
-
};
|
|
40
|
-
declare const errors: typeof niceErrors;
|
|
41
|
-
export declare function die(error: string | keyof typeof errors, ...args: any[]): never;
|
|
42
|
-
export {};
|
|
1
|
+
declare const niceErrors: {
|
|
2
|
+
readonly 0: "Invalid value for configuration 'enforceActions', expected 'never', 'always' or 'observed'";
|
|
3
|
+
readonly 1: (annotationType: any, key: PropertyKey) => string;
|
|
4
|
+
readonly 5: "'keys()' can only be used on observable objects, arrays, sets and maps";
|
|
5
|
+
readonly 6: "'values()' can only be used on observable objects, arrays, sets and maps";
|
|
6
|
+
readonly 7: "'entries()' can only be used on observable objects, arrays and maps";
|
|
7
|
+
readonly 8: "'set()' can only be used on observable objects, arrays and maps";
|
|
8
|
+
readonly 9: "'remove()' can only be used on observable objects, arrays and maps";
|
|
9
|
+
readonly 10: "'has()' can only be used on observable objects, arrays and maps";
|
|
10
|
+
readonly 11: "'get()' can only be used on observable objects, arrays and maps";
|
|
11
|
+
readonly 12: "Invalid annotation";
|
|
12
|
+
readonly 13: "Dynamic observable objects cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)";
|
|
13
|
+
readonly 14: "Intercept handlers should return nothing or a change object";
|
|
14
|
+
readonly 15: "Observable arrays cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)";
|
|
15
|
+
readonly 16: "Modification exception: the internal structure of an observable array was changed.";
|
|
16
|
+
readonly 17: (index: any, length: any) => string;
|
|
17
|
+
readonly 18: "mobx.map requires Map polyfill for the current browser. Check babel-polyfill or core-js/es6/map.js";
|
|
18
|
+
readonly 19: (other: any) => string;
|
|
19
|
+
readonly 20: (other: any) => string;
|
|
20
|
+
readonly 21: (dataStructure: any) => string;
|
|
21
|
+
readonly 22: "mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js";
|
|
22
|
+
readonly 23: "It is not possible to get index atoms from arrays";
|
|
23
|
+
readonly 24: (thing: any) => string;
|
|
24
|
+
readonly 25: (property: any, name: any) => string;
|
|
25
|
+
readonly 26: "please specify a property";
|
|
26
|
+
readonly 27: (property: any, name: any) => string;
|
|
27
|
+
readonly 28: (thing: any) => string;
|
|
28
|
+
readonly 29: "Expecting some object";
|
|
29
|
+
readonly 30: "invalid action stack. did you forget to finish an action?";
|
|
30
|
+
readonly 31: "missing option for computed: get";
|
|
31
|
+
readonly 32: (name: any, derivation: any) => string;
|
|
32
|
+
readonly 33: (name: any) => string;
|
|
33
|
+
readonly 34: (name: any) => string;
|
|
34
|
+
readonly 35: "There are multiple, different versions of MobX active. Make sure MobX is loaded only once or use `configure({ isolateGlobalState: true })`";
|
|
35
|
+
readonly 36: "isolateGlobalState should be called before MobX is running any reactions";
|
|
36
|
+
readonly 37: (method: any) => string;
|
|
37
|
+
readonly 38: "'ownKeys()' can only be used on observable objects";
|
|
38
|
+
readonly 39: "'defineProperty()' can only be used on observable objects";
|
|
39
|
+
};
|
|
40
|
+
declare const errors: typeof niceErrors;
|
|
41
|
+
export declare function die(error: string | keyof typeof errors, ...args: any[]): never;
|
|
42
|
+
export {};
|