mobx 4.15.3 → 4.15.7
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 +28 -0
- package/README.md +19 -10
- package/lib/api/action.d.ts +13 -13
- package/lib/api/actiondecorator.d.ts +27 -27
- package/lib/api/autorun.d.ts +24 -24
- package/lib/api/become-observed.d.ts +5 -5
- package/lib/api/computed.d.ts +14 -14
- package/lib/api/configure.d.ts +19 -19
- package/lib/api/decorate.d.ts +6 -6
- package/lib/api/extendobservable.d.ts +7 -7
- package/lib/api/extras.d.ts +10 -10
- package/lib/api/flow.d.ts +9 -9
- package/lib/api/intercept-read.d.ts +8 -8
- package/lib/api/intercept.d.ts +8 -8
- package/lib/api/iscomputed.d.ts +3 -3
- package/lib/api/isobservable.d.ts +2 -2
- package/lib/api/object-api.d.ts +34 -34
- package/lib/api/observable.d.ts +54 -54
- package/lib/api/observabledecorator.d.ts +6 -6
- package/lib/api/observe.d.ts +8 -8
- package/lib/api/tojs.d.ts +11 -11
- package/lib/api/trace.d.ts +3 -3
- package/lib/api/transaction.d.ts +8 -8
- package/lib/api/when.d.ts +15 -15
- package/lib/core/action.d.ts +22 -22
- package/lib/core/atom.d.ts +40 -40
- package/lib/core/computedvalue.d.ts +93 -93
- package/lib/core/derivation.d.ts +74 -74
- package/lib/core/globalstate.d.ts +106 -106
- package/lib/core/observable.d.ts +44 -44
- package/lib/core/reaction.d.ts +63 -63
- package/lib/core/spy.d.ts +6 -6
- package/lib/index.js +7 -0
- package/lib/internal.d.ts +44 -44
- package/lib/mobx.d.ts +19 -19
- package/lib/mobx.es6.js +4436 -4293
- package/lib/mobx.js +4520 -4387
- package/lib/mobx.min.js +15 -1
- package/lib/mobx.module.js +4535 -4388
- package/lib/mobx.umd.js +4536 -4389
- package/lib/mobx.umd.min.js +15 -1
- package/lib/types/intercept-utils.d.ts +9 -9
- package/lib/types/listen-utils.d.ts +8 -8
- package/lib/types/modifiers.d.ts +7 -7
- package/lib/types/observablearray.d.ts +78 -78
- package/lib/types/observablemap.d.ts +83 -83
- package/lib/types/observableobject.d.ts +65 -65
- package/lib/types/observableset.d.ts +49 -49
- package/lib/types/observablevalue.d.ts +37 -37
- package/lib/types/type-utils.d.ts +4 -4
- package/lib/utils/comparer.d.ts +14 -14
- package/lib/utils/decorators2.d.ts +7 -7
- package/lib/utils/eq.d.ts +1 -1
- package/lib/utils/iterable.d.ts +5 -5
- package/lib/utils/utils.d.ts +42 -43
- package/package.json +3 -13
package/lib/core/derivation.d.ts
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import { IDepTreeNode, IObservable, IAtom } from "../internal";
|
|
2
|
-
export declare enum IDerivationState {
|
|
3
|
-
NOT_TRACKING = -1,
|
|
4
|
-
UP_TO_DATE = 0,
|
|
5
|
-
POSSIBLY_STALE = 1,
|
|
6
|
-
STALE = 2
|
|
7
|
-
}
|
|
8
|
-
export declare enum TraceMode {
|
|
9
|
-
NONE = 0,
|
|
10
|
-
LOG = 1,
|
|
11
|
-
BREAK = 2
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* A derivation is everything that can be derived from the state (all the atoms) in a pure manner.
|
|
15
|
-
* See https://medium.com/@mweststrate/becoming-fully-reactive-an-in-depth-explanation-of-mobservable-55995262a254#.xvbh6qd74
|
|
16
|
-
*/
|
|
17
|
-
export interface IDerivation extends IDepTreeNode {
|
|
18
|
-
observing: IObservable[];
|
|
19
|
-
newObserving: null | IObservable[];
|
|
20
|
-
dependenciesState: IDerivationState;
|
|
21
|
-
/**
|
|
22
|
-
* Id of the current run of a derivation. Each time the derivation is tracked
|
|
23
|
-
* this number is increased by one. This number is globally unique
|
|
24
|
-
*/
|
|
25
|
-
runId: number;
|
|
26
|
-
/**
|
|
27
|
-
* amount of dependencies used by the derivation in this run, which has not been bound yet.
|
|
28
|
-
*/
|
|
29
|
-
unboundDepsCount: number;
|
|
30
|
-
__mapid: string;
|
|
31
|
-
onBecomeStale(): void;
|
|
32
|
-
isTracing: TraceMode;
|
|
33
|
-
/**
|
|
34
|
-
* warn if the derivation has no dependencies after creation/update
|
|
35
|
-
*/
|
|
36
|
-
requiresObservable?: boolean;
|
|
37
|
-
}
|
|
38
|
-
export declare class CaughtException {
|
|
39
|
-
cause: any;
|
|
40
|
-
constructor(cause: any);
|
|
41
|
-
}
|
|
42
|
-
export declare function isCaughtException(e: any): e is CaughtException;
|
|
43
|
-
/**
|
|
44
|
-
* Finds out whether any dependency of the derivation has actually changed.
|
|
45
|
-
* If dependenciesState is 1 then it will recalculate dependencies,
|
|
46
|
-
* if any dependency changed it will propagate it by changing dependenciesState to 2.
|
|
47
|
-
*
|
|
48
|
-
* By iterating over the dependencies in the same order that they were reported and
|
|
49
|
-
* stopping on the first change, all the recalculations are only called for ComputedValues
|
|
50
|
-
* that will be tracked by derivation. That is because we assume that if the first x
|
|
51
|
-
* dependencies of the derivation doesn't change then the derivation should run the same way
|
|
52
|
-
* up until accessing x-th dependency.
|
|
53
|
-
*/
|
|
54
|
-
export declare function shouldCompute(derivation: IDerivation): boolean;
|
|
55
|
-
export declare function isComputingDerivation(): boolean;
|
|
56
|
-
export declare function checkIfStateModificationsAreAllowed(atom: IAtom): void;
|
|
57
|
-
export declare function checkIfStateReadsAreAllowed(observable: IObservable): void;
|
|
58
|
-
/**
|
|
59
|
-
* Executes the provided function `f` and tracks which observables are being accessed.
|
|
60
|
-
* The tracking information is stored on the `derivation` object and the derivation is registered
|
|
61
|
-
* as observer of any of the accessed observables.
|
|
62
|
-
*/
|
|
63
|
-
export declare function trackDerivedFunction<T>(derivation: IDerivation, f: () => T, context: any): any;
|
|
64
|
-
export declare function clearObserving(derivation: IDerivation): void;
|
|
65
|
-
export declare function untracked<T>(action: () => T): T;
|
|
66
|
-
export declare function untrackedStart(): IDerivation | null;
|
|
67
|
-
export declare function untrackedEnd(prev: IDerivation | null): void;
|
|
68
|
-
export declare function allowStateReadsStart(allowStateReads: boolean): boolean;
|
|
69
|
-
export declare function allowStateReadsEnd(prev: boolean): void;
|
|
70
|
-
/**
|
|
71
|
-
* needed to keep `lowestObserverState` correct. when changing from (2 or 1) to 0
|
|
72
|
-
*
|
|
73
|
-
*/
|
|
74
|
-
export declare function changeDependenciesStateTo0(derivation: IDerivation): void;
|
|
1
|
+
import { IDepTreeNode, IObservable, IAtom } from "../internal";
|
|
2
|
+
export declare enum IDerivationState {
|
|
3
|
+
NOT_TRACKING = -1,
|
|
4
|
+
UP_TO_DATE = 0,
|
|
5
|
+
POSSIBLY_STALE = 1,
|
|
6
|
+
STALE = 2
|
|
7
|
+
}
|
|
8
|
+
export declare enum TraceMode {
|
|
9
|
+
NONE = 0,
|
|
10
|
+
LOG = 1,
|
|
11
|
+
BREAK = 2
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A derivation is everything that can be derived from the state (all the atoms) in a pure manner.
|
|
15
|
+
* See https://medium.com/@mweststrate/becoming-fully-reactive-an-in-depth-explanation-of-mobservable-55995262a254#.xvbh6qd74
|
|
16
|
+
*/
|
|
17
|
+
export interface IDerivation extends IDepTreeNode {
|
|
18
|
+
observing: IObservable[];
|
|
19
|
+
newObserving: null | IObservable[];
|
|
20
|
+
dependenciesState: IDerivationState;
|
|
21
|
+
/**
|
|
22
|
+
* Id of the current run of a derivation. Each time the derivation is tracked
|
|
23
|
+
* this number is increased by one. This number is globally unique
|
|
24
|
+
*/
|
|
25
|
+
runId: number;
|
|
26
|
+
/**
|
|
27
|
+
* amount of dependencies used by the derivation in this run, which has not been bound yet.
|
|
28
|
+
*/
|
|
29
|
+
unboundDepsCount: number;
|
|
30
|
+
__mapid: string;
|
|
31
|
+
onBecomeStale(): void;
|
|
32
|
+
isTracing: TraceMode;
|
|
33
|
+
/**
|
|
34
|
+
* warn if the derivation has no dependencies after creation/update
|
|
35
|
+
*/
|
|
36
|
+
requiresObservable?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare class CaughtException {
|
|
39
|
+
cause: any;
|
|
40
|
+
constructor(cause: any);
|
|
41
|
+
}
|
|
42
|
+
export declare function isCaughtException(e: any): e is CaughtException;
|
|
43
|
+
/**
|
|
44
|
+
* Finds out whether any dependency of the derivation has actually changed.
|
|
45
|
+
* If dependenciesState is 1 then it will recalculate dependencies,
|
|
46
|
+
* if any dependency changed it will propagate it by changing dependenciesState to 2.
|
|
47
|
+
*
|
|
48
|
+
* By iterating over the dependencies in the same order that they were reported and
|
|
49
|
+
* stopping on the first change, all the recalculations are only called for ComputedValues
|
|
50
|
+
* that will be tracked by derivation. That is because we assume that if the first x
|
|
51
|
+
* dependencies of the derivation doesn't change then the derivation should run the same way
|
|
52
|
+
* up until accessing x-th dependency.
|
|
53
|
+
*/
|
|
54
|
+
export declare function shouldCompute(derivation: IDerivation): boolean;
|
|
55
|
+
export declare function isComputingDerivation(): boolean;
|
|
56
|
+
export declare function checkIfStateModificationsAreAllowed(atom: IAtom): void;
|
|
57
|
+
export declare function checkIfStateReadsAreAllowed(observable: IObservable): void;
|
|
58
|
+
/**
|
|
59
|
+
* Executes the provided function `f` and tracks which observables are being accessed.
|
|
60
|
+
* The tracking information is stored on the `derivation` object and the derivation is registered
|
|
61
|
+
* as observer of any of the accessed observables.
|
|
62
|
+
*/
|
|
63
|
+
export declare function trackDerivedFunction<T>(derivation: IDerivation, f: () => T, context: any): any;
|
|
64
|
+
export declare function clearObserving(derivation: IDerivation): void;
|
|
65
|
+
export declare function untracked<T>(action: () => T): T;
|
|
66
|
+
export declare function untrackedStart(): IDerivation | null;
|
|
67
|
+
export declare function untrackedEnd(prev: IDerivation | null): void;
|
|
68
|
+
export declare function allowStateReadsStart(allowStateReads: boolean): boolean;
|
|
69
|
+
export declare function allowStateReadsEnd(prev: boolean): void;
|
|
70
|
+
/**
|
|
71
|
+
* needed to keep `lowestObserverState` correct. when changing from (2 or 1) to 0
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
export declare function changeDependenciesStateTo0(derivation: IDerivation): void;
|
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
import { IDerivation, IObservable, Reaction } from "../internal";
|
|
2
|
-
export declare type IUNCHANGED = {};
|
|
3
|
-
export declare class MobXGlobals {
|
|
4
|
-
/**
|
|
5
|
-
* MobXGlobals version.
|
|
6
|
-
* MobX compatiblity with other versions loaded in memory as long as this version matches.
|
|
7
|
-
* It indicates that the global state still stores similar information
|
|
8
|
-
*
|
|
9
|
-
* N.B: this version is unrelated to the package version of MobX, and is only the version of the
|
|
10
|
-
* internal state storage of MobX, and can be the same across many different package versions
|
|
11
|
-
*/
|
|
12
|
-
version: number;
|
|
13
|
-
/**
|
|
14
|
-
* globally unique token to signal unchanged
|
|
15
|
-
*/
|
|
16
|
-
UNCHANGED: IUNCHANGED;
|
|
17
|
-
/**
|
|
18
|
-
* Currently running derivation
|
|
19
|
-
*/
|
|
20
|
-
trackingDerivation: IDerivation | null;
|
|
21
|
-
/**
|
|
22
|
-
* Are we running a computation currently? (not a reaction)
|
|
23
|
-
*/
|
|
24
|
-
computationDepth: number;
|
|
25
|
-
/**
|
|
26
|
-
* Each time a derivation is tracked, it is assigned a unique run-id
|
|
27
|
-
*/
|
|
28
|
-
runId: number;
|
|
29
|
-
/**
|
|
30
|
-
* 'guid' for general purpose. Will be persisted amongst resets.
|
|
31
|
-
*/
|
|
32
|
-
mobxGuid: number;
|
|
33
|
-
/**
|
|
34
|
-
* Are we in a batch block? (and how many of them)
|
|
35
|
-
*/
|
|
36
|
-
inBatch: number;
|
|
37
|
-
/**
|
|
38
|
-
* Observables that don't have observers anymore, and are about to be
|
|
39
|
-
* suspended, unless somebody else accesses it in the same batch
|
|
40
|
-
*
|
|
41
|
-
* @type {IObservable[]}
|
|
42
|
-
*/
|
|
43
|
-
pendingUnobservations: IObservable[];
|
|
44
|
-
/**
|
|
45
|
-
* List of scheduled, not yet executed, reactions.
|
|
46
|
-
*/
|
|
47
|
-
pendingReactions: Reaction[];
|
|
48
|
-
/**
|
|
49
|
-
* Are we currently processing reactions?
|
|
50
|
-
*/
|
|
51
|
-
isRunningReactions: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Is it allowed to change observables at this point?
|
|
54
|
-
* In general, MobX doesn't allow that when running computations and React.render.
|
|
55
|
-
* To ensure that those functions stay pure.
|
|
56
|
-
*/
|
|
57
|
-
allowStateChanges: boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Is it allowed to read observables at this point?
|
|
60
|
-
* Used to hold the state needed for `observableRequiresReaction`
|
|
61
|
-
*/
|
|
62
|
-
allowStateReads: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* If strict mode is enabled, state changes are by default not allowed
|
|
65
|
-
*/
|
|
66
|
-
enforceActions: boolean | "strict";
|
|
67
|
-
/**
|
|
68
|
-
* Spy callbacks
|
|
69
|
-
*/
|
|
70
|
-
spyListeners: {
|
|
71
|
-
(change: any): void;
|
|
72
|
-
}[];
|
|
73
|
-
/**
|
|
74
|
-
* Globally attached error handlers that react specifically to errors in reactions
|
|
75
|
-
*/
|
|
76
|
-
globalReactionErrorHandlers: ((error: any, derivation: IDerivation) => void)[];
|
|
77
|
-
/**
|
|
78
|
-
* Warn if computed values are accessed outside a reactive context
|
|
79
|
-
*/
|
|
80
|
-
computedRequiresReaction: boolean;
|
|
81
|
-
/**
|
|
82
|
-
* (Experimental)
|
|
83
|
-
* Warn if you try to create to derivation / reactive context without accessing any observable.
|
|
84
|
-
*/
|
|
85
|
-
reactionRequiresObservable: boolean;
|
|
86
|
-
/**
|
|
87
|
-
* (Experimental)
|
|
88
|
-
* Warn if observables are accessed outside a reactive context
|
|
89
|
-
*/
|
|
90
|
-
observableRequiresReaction: boolean;
|
|
91
|
-
/**
|
|
92
|
-
* Allows overwriting of computed properties, useful in tests but not prod as it can cause
|
|
93
|
-
* memory leaks. See https://github.com/mobxjs/mobx/issues/1867
|
|
94
|
-
*/
|
|
95
|
-
computedConfigurable: boolean;
|
|
96
|
-
disableErrorBoundaries: boolean;
|
|
97
|
-
suppressReactionErrors: boolean;
|
|
98
|
-
}
|
|
99
|
-
export declare let globalState: MobXGlobals;
|
|
100
|
-
export declare function isolateGlobalState(): void;
|
|
101
|
-
export declare function getGlobalState(): any;
|
|
102
|
-
/**
|
|
103
|
-
* For testing purposes only; this will break the internal state of existing observables,
|
|
104
|
-
* but can be used to get back at a stable state after throwing errors
|
|
105
|
-
*/
|
|
106
|
-
export declare function resetGlobalState(): void;
|
|
1
|
+
import { IDerivation, IObservable, Reaction } from "../internal";
|
|
2
|
+
export declare type IUNCHANGED = {};
|
|
3
|
+
export declare class MobXGlobals {
|
|
4
|
+
/**
|
|
5
|
+
* MobXGlobals version.
|
|
6
|
+
* MobX compatiblity with other versions loaded in memory as long as this version matches.
|
|
7
|
+
* It indicates that the global state still stores similar information
|
|
8
|
+
*
|
|
9
|
+
* N.B: this version is unrelated to the package version of MobX, and is only the version of the
|
|
10
|
+
* internal state storage of MobX, and can be the same across many different package versions
|
|
11
|
+
*/
|
|
12
|
+
version: number;
|
|
13
|
+
/**
|
|
14
|
+
* globally unique token to signal unchanged
|
|
15
|
+
*/
|
|
16
|
+
UNCHANGED: IUNCHANGED;
|
|
17
|
+
/**
|
|
18
|
+
* Currently running derivation
|
|
19
|
+
*/
|
|
20
|
+
trackingDerivation: IDerivation | null;
|
|
21
|
+
/**
|
|
22
|
+
* Are we running a computation currently? (not a reaction)
|
|
23
|
+
*/
|
|
24
|
+
computationDepth: number;
|
|
25
|
+
/**
|
|
26
|
+
* Each time a derivation is tracked, it is assigned a unique run-id
|
|
27
|
+
*/
|
|
28
|
+
runId: number;
|
|
29
|
+
/**
|
|
30
|
+
* 'guid' for general purpose. Will be persisted amongst resets.
|
|
31
|
+
*/
|
|
32
|
+
mobxGuid: number;
|
|
33
|
+
/**
|
|
34
|
+
* Are we in a batch block? (and how many of them)
|
|
35
|
+
*/
|
|
36
|
+
inBatch: number;
|
|
37
|
+
/**
|
|
38
|
+
* Observables that don't have observers anymore, and are about to be
|
|
39
|
+
* suspended, unless somebody else accesses it in the same batch
|
|
40
|
+
*
|
|
41
|
+
* @type {IObservable[]}
|
|
42
|
+
*/
|
|
43
|
+
pendingUnobservations: IObservable[];
|
|
44
|
+
/**
|
|
45
|
+
* List of scheduled, not yet executed, reactions.
|
|
46
|
+
*/
|
|
47
|
+
pendingReactions: Reaction[];
|
|
48
|
+
/**
|
|
49
|
+
* Are we currently processing reactions?
|
|
50
|
+
*/
|
|
51
|
+
isRunningReactions: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Is it allowed to change observables at this point?
|
|
54
|
+
* In general, MobX doesn't allow that when running computations and React.render.
|
|
55
|
+
* To ensure that those functions stay pure.
|
|
56
|
+
*/
|
|
57
|
+
allowStateChanges: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Is it allowed to read observables at this point?
|
|
60
|
+
* Used to hold the state needed for `observableRequiresReaction`
|
|
61
|
+
*/
|
|
62
|
+
allowStateReads: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* If strict mode is enabled, state changes are by default not allowed
|
|
65
|
+
*/
|
|
66
|
+
enforceActions: boolean | "strict";
|
|
67
|
+
/**
|
|
68
|
+
* Spy callbacks
|
|
69
|
+
*/
|
|
70
|
+
spyListeners: {
|
|
71
|
+
(change: any): void;
|
|
72
|
+
}[];
|
|
73
|
+
/**
|
|
74
|
+
* Globally attached error handlers that react specifically to errors in reactions
|
|
75
|
+
*/
|
|
76
|
+
globalReactionErrorHandlers: ((error: any, derivation: IDerivation) => void)[];
|
|
77
|
+
/**
|
|
78
|
+
* Warn if computed values are accessed outside a reactive context
|
|
79
|
+
*/
|
|
80
|
+
computedRequiresReaction: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* (Experimental)
|
|
83
|
+
* Warn if you try to create to derivation / reactive context without accessing any observable.
|
|
84
|
+
*/
|
|
85
|
+
reactionRequiresObservable: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* (Experimental)
|
|
88
|
+
* Warn if observables are accessed outside a reactive context
|
|
89
|
+
*/
|
|
90
|
+
observableRequiresReaction: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Allows overwriting of computed properties, useful in tests but not prod as it can cause
|
|
93
|
+
* memory leaks. See https://github.com/mobxjs/mobx/issues/1867
|
|
94
|
+
*/
|
|
95
|
+
computedConfigurable: boolean;
|
|
96
|
+
disableErrorBoundaries: boolean;
|
|
97
|
+
suppressReactionErrors: boolean;
|
|
98
|
+
}
|
|
99
|
+
export declare let globalState: MobXGlobals;
|
|
100
|
+
export declare function isolateGlobalState(): void;
|
|
101
|
+
export declare function getGlobalState(): any;
|
|
102
|
+
/**
|
|
103
|
+
* For testing purposes only; this will break the internal state of existing observables,
|
|
104
|
+
* but can be used to get back at a stable state after throwing errors
|
|
105
|
+
*/
|
|
106
|
+
export declare function resetGlobalState(): void;
|
package/lib/core/observable.d.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { 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: IDerivation[];
|
|
18
|
-
observersIndexes: {};
|
|
19
|
-
onBecomeUnobserved(): void;
|
|
20
|
-
onBecomeObserved(): void;
|
|
21
|
-
}
|
|
22
|
-
export declare function hasObservers(observable: IObservable): boolean;
|
|
23
|
-
export declare function getObservers(observable: IObservable): IDerivation[];
|
|
24
|
-
export declare function addObserver(observable: IObservable, node: IDerivation): void;
|
|
25
|
-
export declare function removeObserver(observable: IObservable, node: IDerivation): void;
|
|
26
|
-
export declare function queueForUnobservation(observable: IObservable): void;
|
|
27
|
-
/**
|
|
28
|
-
* Batch starts a transaction, at least for purposes of memoizing ComputedValues when nothing else does.
|
|
29
|
-
* During a batch `onBecomeUnobserved` will be called at most once per observable.
|
|
30
|
-
* Avoids unnecessary recalculations.
|
|
31
|
-
*/
|
|
32
|
-
export declare function startBatch(): void;
|
|
33
|
-
export declare function endBatch(): void;
|
|
34
|
-
export declare function reportObserved(observable: IObservable): boolean;
|
|
35
|
-
/**
|
|
36
|
-
* NOTE: current propagation mechanism will in case of self reruning autoruns behave unexpectedly
|
|
37
|
-
* It will propagate changes to observers from previous run
|
|
38
|
-
* It's hard or maybe impossible (with reasonable perf) to get it right with current approach
|
|
39
|
-
* Hopefully self reruning autoruns aren't a feature people should depend on
|
|
40
|
-
* Also most basic use cases should be ok
|
|
41
|
-
*/
|
|
42
|
-
export declare function propagateChanged(observable: IObservable): void;
|
|
43
|
-
export declare function propagateChangeConfirmed(observable: IObservable): void;
|
|
44
|
-
export declare function propagateMaybeChanged(observable: IObservable): void;
|
|
1
|
+
import { 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: IDerivation[];
|
|
18
|
+
observersIndexes: {};
|
|
19
|
+
onBecomeUnobserved(): void;
|
|
20
|
+
onBecomeObserved(): void;
|
|
21
|
+
}
|
|
22
|
+
export declare function hasObservers(observable: IObservable): boolean;
|
|
23
|
+
export declare function getObservers(observable: IObservable): IDerivation[];
|
|
24
|
+
export declare function addObserver(observable: IObservable, node: IDerivation): void;
|
|
25
|
+
export declare function removeObserver(observable: IObservable, node: IDerivation): void;
|
|
26
|
+
export declare function queueForUnobservation(observable: IObservable): void;
|
|
27
|
+
/**
|
|
28
|
+
* Batch starts a transaction, at least for purposes of memoizing ComputedValues when nothing else does.
|
|
29
|
+
* During a batch `onBecomeUnobserved` will be called at most once per observable.
|
|
30
|
+
* Avoids unnecessary recalculations.
|
|
31
|
+
*/
|
|
32
|
+
export declare function startBatch(): void;
|
|
33
|
+
export declare function endBatch(): void;
|
|
34
|
+
export declare function reportObserved(observable: IObservable): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* NOTE: current propagation mechanism will in case of self reruning autoruns behave unexpectedly
|
|
37
|
+
* It will propagate changes to observers from previous run
|
|
38
|
+
* It's hard or maybe impossible (with reasonable perf) to get it right with current approach
|
|
39
|
+
* Hopefully self reruning autoruns aren't a feature people should depend on
|
|
40
|
+
* Also most basic use cases should be ok
|
|
41
|
+
*/
|
|
42
|
+
export declare function propagateChanged(observable: IObservable): void;
|
|
43
|
+
export declare function propagateChangeConfirmed(observable: IObservable): void;
|
|
44
|
+
export declare function propagateMaybeChanged(observable: IObservable): void;
|
package/lib/core/reaction.d.ts
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { IDerivation, IDerivationState, TraceMode, IObservable, Lambda } 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: boolean;
|
|
33
|
-
observing: IObservable[];
|
|
34
|
-
newObserving: IObservable[];
|
|
35
|
-
dependenciesState: IDerivationState;
|
|
36
|
-
diffValue: number;
|
|
37
|
-
runId: number;
|
|
38
|
-
unboundDepsCount: number;
|
|
39
|
-
__mapid: string;
|
|
40
|
-
isDisposed: boolean;
|
|
41
|
-
_isScheduled: boolean;
|
|
42
|
-
_isTrackPending: boolean;
|
|
43
|
-
_isRunning: boolean;
|
|
44
|
-
isTracing: TraceMode;
|
|
45
|
-
constructor(name: string, onInvalidate: () => void, errorHandler?: ((error: any, derivation: IDerivation) => void) | undefined, requiresObservable?: boolean);
|
|
46
|
-
onBecomeStale(): void;
|
|
47
|
-
schedule(): void;
|
|
48
|
-
isScheduled(): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* internal, use schedule() if you intend to kick off a reaction
|
|
51
|
-
*/
|
|
52
|
-
runReaction(): void;
|
|
53
|
-
track(fn: () => void): void;
|
|
54
|
-
reportExceptionInDerivation(error: any): void;
|
|
55
|
-
dispose(): void;
|
|
56
|
-
getDisposer(): IReactionDisposer;
|
|
57
|
-
toString(): string;
|
|
58
|
-
trace(enterBreakPoint?: boolean): void;
|
|
59
|
-
}
|
|
60
|
-
export declare function onReactionError(handler: (error: any, derivation: IDerivation) => void): Lambda;
|
|
61
|
-
export declare function runReactions(): void;
|
|
62
|
-
export declare const isReaction: (x: any) => x is Reaction;
|
|
63
|
-
export declare function setReactionScheduler(fn: (f: () => void) => void): void;
|
|
1
|
+
import { IDerivation, IDerivationState, TraceMode, IObservable, Lambda } 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: boolean;
|
|
33
|
+
observing: IObservable[];
|
|
34
|
+
newObserving: IObservable[];
|
|
35
|
+
dependenciesState: IDerivationState;
|
|
36
|
+
diffValue: number;
|
|
37
|
+
runId: number;
|
|
38
|
+
unboundDepsCount: number;
|
|
39
|
+
__mapid: string;
|
|
40
|
+
isDisposed: boolean;
|
|
41
|
+
_isScheduled: boolean;
|
|
42
|
+
_isTrackPending: boolean;
|
|
43
|
+
_isRunning: boolean;
|
|
44
|
+
isTracing: TraceMode;
|
|
45
|
+
constructor(name: string, onInvalidate: () => void, errorHandler?: ((error: any, derivation: IDerivation) => void) | undefined, requiresObservable?: boolean);
|
|
46
|
+
onBecomeStale(): void;
|
|
47
|
+
schedule(): void;
|
|
48
|
+
isScheduled(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* internal, use schedule() if you intend to kick off a reaction
|
|
51
|
+
*/
|
|
52
|
+
runReaction(): void;
|
|
53
|
+
track(fn: () => void): void;
|
|
54
|
+
reportExceptionInDerivation(error: any): void;
|
|
55
|
+
dispose(): void;
|
|
56
|
+
getDisposer(): IReactionDisposer;
|
|
57
|
+
toString(): string;
|
|
58
|
+
trace(enterBreakPoint?: boolean): void;
|
|
59
|
+
}
|
|
60
|
+
export declare function onReactionError(handler: (error: any, derivation: IDerivation) => void): Lambda;
|
|
61
|
+
export declare function runReactions(): void;
|
|
62
|
+
export declare const isReaction: (x: any) => x is Reaction;
|
|
63
|
+
export declare function setReactionScheduler(fn: (f: () => void) => void): void;
|
package/lib/core/spy.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Lambda } from "../internal";
|
|
2
|
-
export declare function isSpyEnabled(): boolean;
|
|
3
|
-
export declare function spyReport(event: any): void;
|
|
4
|
-
export declare function spyReportStart(event: any): void;
|
|
5
|
-
export declare function spyReportEnd(change?: any): void;
|
|
6
|
-
export declare function spy(listener: (change: any) => void): Lambda;
|
|
1
|
+
import { Lambda } from "../internal";
|
|
2
|
+
export declare function isSpyEnabled(): boolean;
|
|
3
|
+
export declare function spyReport(event: any): void;
|
|
4
|
+
export declare function spyReportStart(event: any): void;
|
|
5
|
+
export declare function spyReportEnd(change?: any): void;
|
|
6
|
+
export declare function spy(listener: (change: any) => void): Lambda;
|