mobx 5.15.3 → 5.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 +18 -18
- 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 +44 -44
- 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 +37 -37
- package/lib/core/computedvalue.d.ts +95 -95
- package/lib/core/derivation.d.ts +74 -74
- package/lib/core/globalstate.d.ts +107 -107
- package/lib/core/observable.d.ts +45 -45
- 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 +45 -45
- package/lib/mobx.d.ts +18 -18
- package/lib/mobx.es6.js +4317 -4157
- package/lib/mobx.js +4513 -4347
- package/lib/mobx.min.js +15 -1
- package/lib/mobx.module.js +4530 -4348
- package/lib/mobx.umd.js +4531 -4349
- package/lib/mobx.umd.min.js +15 -1
- package/lib/types/dynamicobject.d.ts +1 -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 +42 -42
- package/lib/types/observablemap.d.ts +83 -83
- package/lib/types/observableobject.d.ts +67 -67
- package/lib/types/observableset.d.ts +49 -49
- package/lib/types/observablevalue.d.ts +38 -38
- package/lib/types/type-utils.d.ts +4 -4
- package/lib/utils/comparer.d.ts +14 -14
- package/lib/utils/decorators.d.ts +9 -9
- package/lib/utils/eq.d.ts +1 -1
- package/lib/utils/iterable.d.ts +1 -1
- package/lib/utils/utils.d.ts +43 -43
- package/package.json +3 -13
|
@@ -1,107 +1,107 @@
|
|
|
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 function getGlobal(): any;
|
|
100
|
-
export declare let globalState: MobXGlobals;
|
|
101
|
-
export declare function isolateGlobalState(): void;
|
|
102
|
-
export declare function getGlobalState(): any;
|
|
103
|
-
/**
|
|
104
|
-
* For testing purposes only; this will break the internal state of existing observables,
|
|
105
|
-
* but can be used to get back at a stable state after throwing errors
|
|
106
|
-
*/
|
|
107
|
-
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 function getGlobal(): any;
|
|
100
|
+
export declare let globalState: MobXGlobals;
|
|
101
|
+
export declare function isolateGlobalState(): void;
|
|
102
|
+
export declare function getGlobalState(): any;
|
|
103
|
+
/**
|
|
104
|
+
* For testing purposes only; this will break the internal state of existing observables,
|
|
105
|
+
* but can be used to get back at a stable state after throwing errors
|
|
106
|
+
*/
|
|
107
|
+
export declare function resetGlobalState(): void;
|
package/lib/core/observable.d.ts
CHANGED
|
@@ -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
|
-
onBecomeUnobserved(): void;
|
|
19
|
-
onBecomeObserved(): void;
|
|
20
|
-
onBecomeUnobservedListeners: Set<Lambda> | undefined;
|
|
21
|
-
onBecomeObservedListeners: 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
|
+
onBecomeUnobserved(): void;
|
|
19
|
+
onBecomeObserved(): void;
|
|
20
|
+
onBecomeUnobservedListeners: Set<Lambda> | undefined;
|
|
21
|
+
onBecomeObservedListeners: 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/lib/core/reaction.d.ts
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { IDerivation, IDerivationState, IObservable, Lambda, TraceMode } 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, IObservable, Lambda, TraceMode } 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;
|
package/lib/index.js
ADDED
package/lib/internal.d.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
export * from "./utils/utils";
|
|
2
|
-
export * from "./core/atom";
|
|
3
|
-
export * from "./utils/comparer";
|
|
4
|
-
export * from "./utils/decorators";
|
|
5
|
-
export * from "./types/modifiers";
|
|
6
|
-
export * from "./api/observabledecorator";
|
|
7
|
-
export * from "./api/observable";
|
|
8
|
-
export * from "./api/computed";
|
|
9
|
-
export * from "./core/action";
|
|
10
|
-
export * from "./types/observablevalue";
|
|
11
|
-
export * from "./core/computedvalue";
|
|
12
|
-
export * from "./core/derivation";
|
|
13
|
-
export * from "./core/globalstate";
|
|
14
|
-
export * from "./core/observable";
|
|
15
|
-
export * from "./core/reaction";
|
|
16
|
-
export * from "./core/spy";
|
|
17
|
-
export * from "./api/actiondecorator";
|
|
18
|
-
export * from "./api/action";
|
|
19
|
-
export * from "./api/autorun";
|
|
20
|
-
export * from "./api/become-observed";
|
|
21
|
-
export * from "./api/configure";
|
|
22
|
-
export * from "./api/decorate";
|
|
23
|
-
export * from "./api/extendobservable";
|
|
24
|
-
export * from "./api/extras";
|
|
25
|
-
export * from "./api/flow";
|
|
26
|
-
export * from "./api/intercept-read";
|
|
27
|
-
export * from "./api/intercept";
|
|
28
|
-
export * from "./api/iscomputed";
|
|
29
|
-
export * from "./api/isobservable";
|
|
30
|
-
export * from "./api/object-api";
|
|
31
|
-
export * from "./api/observe";
|
|
32
|
-
export * from "./api/tojs";
|
|
33
|
-
export * from "./api/trace";
|
|
34
|
-
export * from "./api/transaction";
|
|
35
|
-
export * from "./api/when";
|
|
36
|
-
export * from "./types/dynamicobject";
|
|
37
|
-
export * from "./types/intercept-utils";
|
|
38
|
-
export * from "./types/listen-utils";
|
|
39
|
-
export * from "./types/observablearray";
|
|
40
|
-
export * from "./types/observablemap";
|
|
41
|
-
export * from "./types/observableset";
|
|
42
|
-
export * from "./types/observableobject";
|
|
43
|
-
export * from "./types/type-utils";
|
|
44
|
-
export * from "./utils/eq";
|
|
45
|
-
export * from "./utils/iterable";
|
|
1
|
+
export * from "./utils/utils";
|
|
2
|
+
export * from "./core/atom";
|
|
3
|
+
export * from "./utils/comparer";
|
|
4
|
+
export * from "./utils/decorators";
|
|
5
|
+
export * from "./types/modifiers";
|
|
6
|
+
export * from "./api/observabledecorator";
|
|
7
|
+
export * from "./api/observable";
|
|
8
|
+
export * from "./api/computed";
|
|
9
|
+
export * from "./core/action";
|
|
10
|
+
export * from "./types/observablevalue";
|
|
11
|
+
export * from "./core/computedvalue";
|
|
12
|
+
export * from "./core/derivation";
|
|
13
|
+
export * from "./core/globalstate";
|
|
14
|
+
export * from "./core/observable";
|
|
15
|
+
export * from "./core/reaction";
|
|
16
|
+
export * from "./core/spy";
|
|
17
|
+
export * from "./api/actiondecorator";
|
|
18
|
+
export * from "./api/action";
|
|
19
|
+
export * from "./api/autorun";
|
|
20
|
+
export * from "./api/become-observed";
|
|
21
|
+
export * from "./api/configure";
|
|
22
|
+
export * from "./api/decorate";
|
|
23
|
+
export * from "./api/extendobservable";
|
|
24
|
+
export * from "./api/extras";
|
|
25
|
+
export * from "./api/flow";
|
|
26
|
+
export * from "./api/intercept-read";
|
|
27
|
+
export * from "./api/intercept";
|
|
28
|
+
export * from "./api/iscomputed";
|
|
29
|
+
export * from "./api/isobservable";
|
|
30
|
+
export * from "./api/object-api";
|
|
31
|
+
export * from "./api/observe";
|
|
32
|
+
export * from "./api/tojs";
|
|
33
|
+
export * from "./api/trace";
|
|
34
|
+
export * from "./api/transaction";
|
|
35
|
+
export * from "./api/when";
|
|
36
|
+
export * from "./types/dynamicobject";
|
|
37
|
+
export * from "./types/intercept-utils";
|
|
38
|
+
export * from "./types/listen-utils";
|
|
39
|
+
export * from "./types/observablearray";
|
|
40
|
+
export * from "./types/observablemap";
|
|
41
|
+
export * from "./types/observableset";
|
|
42
|
+
export * from "./types/observableobject";
|
|
43
|
+
export * from "./types/type-utils";
|
|
44
|
+
export * from "./utils/eq";
|
|
45
|
+
export * from "./utils/iterable";
|
package/lib/mobx.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* (c) Michel Weststrate 2015 - 2018
|
|
3
|
-
* MIT Licensed
|
|
4
|
-
*
|
|
5
|
-
* Welcome to the mobx sources! To get an global overview of how MobX internally works,
|
|
6
|
-
* this is a good place to start:
|
|
7
|
-
* https://medium.com/@mweststrate/becoming-fully-reactive-an-in-depth-explanation-of-mobservable-55995262a254#.xvbh6qd74
|
|
8
|
-
*
|
|
9
|
-
* Source folders:
|
|
10
|
-
* ===============
|
|
11
|
-
*
|
|
12
|
-
* - api/ Most of the public static methods exposed by the module can be found here.
|
|
13
|
-
* - core/ Implementation of the MobX algorithm; atoms, derivations, reactions, dependency trees, optimizations. Cool stuff can be found here.
|
|
14
|
-
* - types/ All the magic that is need to have observable objects, arrays and values is in this folder. Including the modifiers like `asFlat`.
|
|
15
|
-
* - utils/ Utility stuff.
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
export { IObservable, IDepTreeNode, Reaction, IReactionPublic, IReactionDisposer, IDerivation, untracked, IDerivationState, IAtom, createAtom, IAction, spy, IComputedValue, IEqualsComparer, comparer, IEnhancer, IInterceptable, IInterceptor, IListenable, IObjectWillChange, IObjectDidChange, IObservableObject, isObservableObject, IValueDidChange, IValueWillChange, IObservableValue, isObservableValue as isBoxedObservable, IObservableArray, IArrayWillChange, IArrayWillSplice, IArrayChange, IArraySplice, isObservableArray, IKeyValueMap, ObservableMap, IMapEntries, IMapEntry, IMapWillChange, IMapDidChange, isObservableMap, IObservableMapInitialValues, ObservableSet, isObservableSet, ISetDidChange, ISetWillChange, IObservableSetInitialValues, transaction, observable, IObservableFactory, IObservableFactories, computed, IComputed, isObservable, isObservableProp, isComputed, isComputedProp, extendObservable, observe, intercept, autorun, IAutorunOptions, reaction, IReactionOptions, when, IWhenOptions, action, isAction, runInAction, IActionFactory, keys, values, entries, set, remove, has, get, decorate, configure, onBecomeObserved, onBecomeUnobserved, flow, FlowCancellationError, isFlowCancellationError, toJS, trace, IObserverTree, IDependencyTree, getDependencyTree, getObserverTree, resetGlobalState as _resetGlobalState, getGlobalState as _getGlobalState, getDebugName, getAtom, getAdministration as _getAdministration, allowStateChanges as _allowStateChanges, allowStateChangesInsideComputed as _allowStateChangesInsideComputed, Lambda, isArrayLike, $mobx, isComputingDerivation as _isComputingDerivation, onReactionError, interceptReads as _interceptReads, IComputedValueOptions, IActionRunInfo, _startAction, _endAction, allowStateReadsStart as _allowStateReadsStart, allowStateReadsEnd as _allowStateReadsEnd } from "./internal";
|
|
1
|
+
/**
|
|
2
|
+
* (c) Michel Weststrate 2015 - 2018
|
|
3
|
+
* MIT Licensed
|
|
4
|
+
*
|
|
5
|
+
* Welcome to the mobx sources! To get an global overview of how MobX internally works,
|
|
6
|
+
* this is a good place to start:
|
|
7
|
+
* https://medium.com/@mweststrate/becoming-fully-reactive-an-in-depth-explanation-of-mobservable-55995262a254#.xvbh6qd74
|
|
8
|
+
*
|
|
9
|
+
* Source folders:
|
|
10
|
+
* ===============
|
|
11
|
+
*
|
|
12
|
+
* - api/ Most of the public static methods exposed by the module can be found here.
|
|
13
|
+
* - core/ Implementation of the MobX algorithm; atoms, derivations, reactions, dependency trees, optimizations. Cool stuff can be found here.
|
|
14
|
+
* - types/ All the magic that is need to have observable objects, arrays and values is in this folder. Including the modifiers like `asFlat`.
|
|
15
|
+
* - utils/ Utility stuff.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export { IObservable, IDepTreeNode, Reaction, IReactionPublic, IReactionDisposer, IDerivation, untracked, IDerivationState, IAtom, createAtom, IAction, spy, IComputedValue, IEqualsComparer, comparer, IEnhancer, IInterceptable, IInterceptor, IListenable, IObjectWillChange, IObjectDidChange, IObservableObject, isObservableObject, IValueDidChange, IValueWillChange, IObservableValue, isObservableValue as isBoxedObservable, IObservableArray, IArrayWillChange, IArrayWillSplice, IArrayChange, IArraySplice, isObservableArray, IKeyValueMap, ObservableMap, IMapEntries, IMapEntry, IMapWillChange, IMapDidChange, isObservableMap, IObservableMapInitialValues, ObservableSet, isObservableSet, ISetDidChange, ISetWillChange, IObservableSetInitialValues, transaction, observable, IObservableFactory, IObservableFactories, computed, IComputed, isObservable, isObservableProp, isComputed, isComputedProp, extendObservable, observe, intercept, autorun, IAutorunOptions, reaction, IReactionOptions, when, IWhenOptions, action, isAction, runInAction, IActionFactory, keys, values, entries, set, remove, has, get, decorate, configure, onBecomeObserved, onBecomeUnobserved, flow, FlowCancellationError, isFlowCancellationError, toJS, trace, IObserverTree, IDependencyTree, getDependencyTree, getObserverTree, resetGlobalState as _resetGlobalState, getGlobalState as _getGlobalState, getDebugName, getAtom, getAdministration as _getAdministration, allowStateChanges as _allowStateChanges, allowStateChangesInsideComputed as _allowStateChangesInsideComputed, Lambda, isArrayLike, $mobx, isComputingDerivation as _isComputingDerivation, onReactionError, interceptReads as _interceptReads, IComputedValueOptions, IActionRunInfo, _startAction, _endAction, allowStateReadsStart as _allowStateReadsStart, allowStateReadsEnd as _allowStateReadsEnd } from "./internal";
|