mobx 6.10.1 → 6.11.0-pre
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 +6 -0
- 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 +428 -260
- 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 +428 -260
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +428 -260
- 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 +428 -260
- 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 +99 -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 +29 -8
- package/src/api/flow.ts +10 -3
- package/src/api/observable.ts +19 -6
- package/src/core/atom.ts +9 -11
- 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/observableobject.ts +16 -0
- package/src/types/overrideannotation.ts +15 -7
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* During a transaction no views are updated until the end of the transaction.
|
|
3
|
-
* The transaction will be run synchronously nonetheless.
|
|
4
|
-
*
|
|
5
|
-
* @param action a function that updates some reactive state
|
|
6
|
-
* @returns any value that was returned by the 'action' parameter.
|
|
7
|
-
*/
|
|
8
|
-
export declare function transaction<T>(action: () => T, thisArg?: undefined): T;
|
|
1
|
+
/**
|
|
2
|
+
* During a transaction no views are updated until the end of the transaction.
|
|
3
|
+
* The transaction will be run synchronously nonetheless.
|
|
4
|
+
*
|
|
5
|
+
* @param action a function that updates some reactive state
|
|
6
|
+
* @returns any value that was returned by the 'action' parameter.
|
|
7
|
+
*/
|
|
8
|
+
export declare function transaction<T>(action: () => T, thisArg?: undefined): T;
|
package/dist/api/when.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { IReactionDisposer, Lambda, GenericAbortSignal } from "../internal";
|
|
2
|
-
export interface IWhenOptions {
|
|
3
|
-
name?: string;
|
|
4
|
-
timeout?: number;
|
|
5
|
-
onError?: (error: any) => void;
|
|
6
|
-
signal?: GenericAbortSignal;
|
|
7
|
-
}
|
|
8
|
-
export declare function when(predicate: () => boolean, opts?: IWhenOptions): Promise<void> & {
|
|
9
|
-
cancel(): void;
|
|
10
|
-
};
|
|
11
|
-
export declare function when(predicate: () => boolean, effect: Lambda, opts?: IWhenOptions): IReactionDisposer;
|
|
1
|
+
import { IReactionDisposer, Lambda, GenericAbortSignal } from "../internal";
|
|
2
|
+
export interface IWhenOptions {
|
|
3
|
+
name?: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
onError?: (error: any) => void;
|
|
6
|
+
signal?: GenericAbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export declare function when(predicate: () => boolean, opts?: IWhenOptions): Promise<void> & {
|
|
9
|
+
cancel(): void;
|
|
10
|
+
};
|
|
11
|
+
export declare function when(predicate: () => boolean, effect: Lambda, opts?: IWhenOptions): IReactionDisposer;
|
package/dist/core/action.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { IDerivation } from "../internal";
|
|
2
|
-
export declare function createAction(actionName: string, fn: Function, autoAction?: boolean, ref?: Object): Function;
|
|
3
|
-
export declare function executeAction(actionName: string, canRunAsDerivation: boolean, fn: Function, scope?: any, args?: IArguments): any;
|
|
4
|
-
export interface IActionRunInfo {
|
|
5
|
-
prevDerivation_: IDerivation | null;
|
|
6
|
-
prevAllowStateChanges_: boolean;
|
|
7
|
-
prevAllowStateReads_: boolean;
|
|
8
|
-
notifySpy_: boolean;
|
|
9
|
-
startTime_: number;
|
|
10
|
-
error_?: any;
|
|
11
|
-
parentActionId_: number;
|
|
12
|
-
actionId_: number;
|
|
13
|
-
runAsAction_?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare function _startAction(actionName: string, canRunAsDerivation: boolean, // true for autoAction
|
|
16
|
-
scope: any, args?: IArguments): IActionRunInfo;
|
|
17
|
-
export declare function _endAction(runInfo: IActionRunInfo): void;
|
|
18
|
-
export declare function allowStateChanges<T>(allowStateChanges: boolean, func: () => T): T;
|
|
19
|
-
export declare function allowStateChangesStart(allowStateChanges: boolean): boolean;
|
|
20
|
-
export declare function allowStateChangesEnd(prev: boolean): void;
|
|
1
|
+
import { IDerivation } from "../internal";
|
|
2
|
+
export declare function createAction(actionName: string, fn: Function, autoAction?: boolean, ref?: Object): Function;
|
|
3
|
+
export declare function executeAction(actionName: string, canRunAsDerivation: boolean, fn: Function, scope?: any, args?: IArguments): any;
|
|
4
|
+
export interface IActionRunInfo {
|
|
5
|
+
prevDerivation_: IDerivation | null;
|
|
6
|
+
prevAllowStateChanges_: boolean;
|
|
7
|
+
prevAllowStateReads_: boolean;
|
|
8
|
+
notifySpy_: boolean;
|
|
9
|
+
startTime_: number;
|
|
10
|
+
error_?: any;
|
|
11
|
+
parentActionId_: number;
|
|
12
|
+
actionId_: number;
|
|
13
|
+
runAsAction_?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function _startAction(actionName: string, canRunAsDerivation: boolean, // true for autoAction
|
|
16
|
+
scope: any, args?: IArguments): IActionRunInfo;
|
|
17
|
+
export declare function _endAction(runInfo: IActionRunInfo): void;
|
|
18
|
+
export declare function allowStateChanges<T>(allowStateChanges: boolean, func: () => T): T;
|
|
19
|
+
export declare function allowStateChangesStart(allowStateChanges: boolean): boolean;
|
|
20
|
+
export declare function allowStateChangesEnd(prev: boolean): void;
|
package/dist/core/atom.d.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { IDerivationState_, IObservable, IDerivation, Lambda } from "../internal";
|
|
2
|
-
export declare const $mobx: unique symbol;
|
|
3
|
-
export interface IAtom extends IObservable {
|
|
4
|
-
reportObserved(): boolean;
|
|
5
|
-
reportChanged(): void;
|
|
6
|
-
}
|
|
7
|
-
export declare class Atom implements IAtom {
|
|
8
|
-
name_: string;
|
|
9
|
-
isPendingUnobservation_: boolean;
|
|
10
|
-
isBeingObserved_: boolean;
|
|
11
|
-
observers_: Set<IDerivation>;
|
|
12
|
-
batchId_: number;
|
|
13
|
-
diffValue_: number;
|
|
14
|
-
lastAccessedBy_: number;
|
|
15
|
-
lowestObserverState_: IDerivationState_;
|
|
16
|
-
/**
|
|
17
|
-
* Create a new atom. For debugging purposes it is recommended to give it a name.
|
|
18
|
-
* The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
|
|
19
|
-
*/
|
|
20
|
-
constructor(name_?: string);
|
|
21
|
-
onBOL: Set<Lambda> | undefined;
|
|
22
|
-
onBUOL: Set<Lambda> | undefined;
|
|
23
|
-
onBO(): void;
|
|
24
|
-
onBUO(): void;
|
|
25
|
-
/**
|
|
26
|
-
* Invoke this method to notify mobx that your atom has been used somehow.
|
|
27
|
-
* Returns true if there is currently a reactive context.
|
|
28
|
-
*/
|
|
29
|
-
reportObserved(): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
|
|
32
|
-
*/
|
|
33
|
-
reportChanged(): void;
|
|
34
|
-
toString(): string;
|
|
35
|
-
}
|
|
36
|
-
export declare const isAtom: (x: any) => x is Atom;
|
|
37
|
-
export declare function createAtom(name: string, onBecomeObservedHandler?: () => void, onBecomeUnobservedHandler?: () => void): IAtom;
|
|
1
|
+
import { IDerivationState_, IObservable, IDerivation, Lambda } from "../internal";
|
|
2
|
+
export declare const $mobx: unique symbol;
|
|
3
|
+
export interface IAtom extends IObservable {
|
|
4
|
+
reportObserved(): boolean;
|
|
5
|
+
reportChanged(): void;
|
|
6
|
+
}
|
|
7
|
+
export declare class Atom implements IAtom {
|
|
8
|
+
name_: string;
|
|
9
|
+
isPendingUnobservation_: boolean;
|
|
10
|
+
isBeingObserved_: boolean;
|
|
11
|
+
observers_: Set<IDerivation>;
|
|
12
|
+
batchId_: number;
|
|
13
|
+
diffValue_: number;
|
|
14
|
+
lastAccessedBy_: number;
|
|
15
|
+
lowestObserverState_: IDerivationState_;
|
|
16
|
+
/**
|
|
17
|
+
* Create a new atom. For debugging purposes it is recommended to give it a name.
|
|
18
|
+
* The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
|
|
19
|
+
*/
|
|
20
|
+
constructor(name_?: string);
|
|
21
|
+
onBOL: Set<Lambda> | undefined;
|
|
22
|
+
onBUOL: Set<Lambda> | undefined;
|
|
23
|
+
onBO(): void;
|
|
24
|
+
onBUO(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Invoke this method to notify mobx that your atom has been used somehow.
|
|
27
|
+
* Returns true if there is currently a reactive context.
|
|
28
|
+
*/
|
|
29
|
+
reportObserved(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
|
|
32
|
+
*/
|
|
33
|
+
reportChanged(): void;
|
|
34
|
+
toString(): string;
|
|
35
|
+
}
|
|
36
|
+
export declare const isAtom: (x: any) => x is Atom;
|
|
37
|
+
export declare function createAtom(name: string, onBecomeObservedHandler?: () => void, onBecomeUnobservedHandler?: () => void): IAtom;
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
import { CaughtException, IDerivation, IDerivationState_, IEqualsComparer, IObservable, Lambda, TraceMode } from "../internal";
|
|
2
|
-
export interface IComputedValue<T> {
|
|
3
|
-
get(): T;
|
|
4
|
-
set(value: T): void;
|
|
5
|
-
}
|
|
6
|
-
export interface IComputedValueOptions<T> {
|
|
7
|
-
get?: () => T;
|
|
8
|
-
set?: (value: T) => void;
|
|
9
|
-
name?: string;
|
|
10
|
-
equals?: IEqualsComparer<T>;
|
|
11
|
-
context?: any;
|
|
12
|
-
requiresReaction?: boolean;
|
|
13
|
-
keepAlive?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export
|
|
16
|
-
type: "update";
|
|
17
|
-
observableKind: "computed";
|
|
18
|
-
object: unknown;
|
|
19
|
-
debugObjectName: string;
|
|
20
|
-
newValue: T;
|
|
21
|
-
oldValue: T | undefined;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* A node in the state dependency root that observes other nodes, and can be observed itself.
|
|
25
|
-
*
|
|
26
|
-
* ComputedValue will remember the result of the computation for the duration of the batch, or
|
|
27
|
-
* while being observed.
|
|
28
|
-
*
|
|
29
|
-
* During this time it will recompute only when one of its direct dependencies changed,
|
|
30
|
-
* but only when it is being accessed with `ComputedValue.get()`.
|
|
31
|
-
*
|
|
32
|
-
* Implementation description:
|
|
33
|
-
* 1. First time it's being accessed it will compute and remember result
|
|
34
|
-
* give back remembered result until 2. happens
|
|
35
|
-
* 2. First time any deep dependency change, propagate POSSIBLY_STALE to all observers, wait for 3.
|
|
36
|
-
* 3. When it's being accessed, recompute if any shallow dependency changed.
|
|
37
|
-
* if result changed: propagate STALE to all observers, that were POSSIBLY_STALE from the last step.
|
|
38
|
-
* go to step 2. either way
|
|
39
|
-
*
|
|
40
|
-
* If at any point it's outside batch and it isn't observed: reset everything and go to 1.
|
|
41
|
-
*/
|
|
42
|
-
export declare class ComputedValue<T> implements IObservable, IComputedValue<T>, IDerivation {
|
|
43
|
-
dependenciesState_: IDerivationState_;
|
|
44
|
-
observing_: IObservable[];
|
|
45
|
-
newObserving_: null;
|
|
46
|
-
isBeingObserved_: boolean;
|
|
47
|
-
isPendingUnobservation_: boolean;
|
|
48
|
-
observers_: Set<IDerivation>;
|
|
49
|
-
diffValue_: number;
|
|
50
|
-
runId_: number;
|
|
51
|
-
lastAccessedBy_: number;
|
|
52
|
-
lowestObserverState_: IDerivationState_;
|
|
53
|
-
unboundDepsCount_: number;
|
|
54
|
-
protected value_: T | undefined | CaughtException;
|
|
55
|
-
name_: string;
|
|
56
|
-
triggeredBy_?: string;
|
|
57
|
-
isComputing_: boolean;
|
|
58
|
-
isRunningSetter_: boolean;
|
|
59
|
-
derivation: () => T;
|
|
60
|
-
setter_?: (value: T) => void;
|
|
61
|
-
isTracing_: TraceMode;
|
|
62
|
-
scope_: Object | undefined;
|
|
63
|
-
private equals_;
|
|
64
|
-
private requiresReaction_;
|
|
65
|
-
keepAlive_: boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Create a new computed value based on a function expression.
|
|
68
|
-
*
|
|
69
|
-
* The `name` property is for debug purposes only.
|
|
70
|
-
*
|
|
71
|
-
* The `equals` property specifies the comparer function to use to determine if a newly produced
|
|
72
|
-
* value differs from the previous value. Two comparers are provided in the library; `defaultComparer`
|
|
73
|
-
* compares based on identity comparison (===), and `structuralComparer` deeply compares the structure.
|
|
74
|
-
* Structural comparison can be convenient if you always produce a new aggregated object and
|
|
75
|
-
* don't want to notify observers if it is structurally the same.
|
|
76
|
-
* This is useful for working with vectors, mouse coordinates etc.
|
|
77
|
-
*/
|
|
78
|
-
constructor(options: IComputedValueOptions<T>);
|
|
79
|
-
onBecomeStale_(): void;
|
|
80
|
-
onBOL: Set<Lambda> | undefined;
|
|
81
|
-
onBUOL: Set<Lambda> | undefined;
|
|
82
|
-
onBO(): void;
|
|
83
|
-
onBUO(): void;
|
|
84
|
-
/**
|
|
85
|
-
* Returns the current value of this computed value.
|
|
86
|
-
* Will evaluate its computation first if needed.
|
|
87
|
-
*/
|
|
88
|
-
get(): T;
|
|
89
|
-
set(value: T): void;
|
|
90
|
-
trackAndCompute(): boolean;
|
|
91
|
-
computeValue_(track: boolean): T | CaughtException;
|
|
92
|
-
suspend_(): void;
|
|
93
|
-
observe_(listener: (change: IComputedDidChange<T>) => void, fireImmediately?: boolean): Lambda;
|
|
94
|
-
warnAboutUntrackedRead_(): void;
|
|
95
|
-
toString(): string;
|
|
96
|
-
valueOf(): T;
|
|
97
|
-
[Symbol.toPrimitive](): T;
|
|
98
|
-
}
|
|
99
|
-
export declare const isComputedValue: (x: any) => x is ComputedValue<unknown>;
|
|
1
|
+
import { CaughtException, IDerivation, IDerivationState_, IEqualsComparer, IObservable, Lambda, TraceMode } from "../internal";
|
|
2
|
+
export interface IComputedValue<T> {
|
|
3
|
+
get(): T;
|
|
4
|
+
set(value: T): void;
|
|
5
|
+
}
|
|
6
|
+
export interface IComputedValueOptions<T> {
|
|
7
|
+
get?: () => T;
|
|
8
|
+
set?: (value: T) => void;
|
|
9
|
+
name?: string;
|
|
10
|
+
equals?: IEqualsComparer<T>;
|
|
11
|
+
context?: any;
|
|
12
|
+
requiresReaction?: boolean;
|
|
13
|
+
keepAlive?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export type IComputedDidChange<T = any> = {
|
|
16
|
+
type: "update";
|
|
17
|
+
observableKind: "computed";
|
|
18
|
+
object: unknown;
|
|
19
|
+
debugObjectName: string;
|
|
20
|
+
newValue: T;
|
|
21
|
+
oldValue: T | undefined;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A node in the state dependency root that observes other nodes, and can be observed itself.
|
|
25
|
+
*
|
|
26
|
+
* ComputedValue will remember the result of the computation for the duration of the batch, or
|
|
27
|
+
* while being observed.
|
|
28
|
+
*
|
|
29
|
+
* During this time it will recompute only when one of its direct dependencies changed,
|
|
30
|
+
* but only when it is being accessed with `ComputedValue.get()`.
|
|
31
|
+
*
|
|
32
|
+
* Implementation description:
|
|
33
|
+
* 1. First time it's being accessed it will compute and remember result
|
|
34
|
+
* give back remembered result until 2. happens
|
|
35
|
+
* 2. First time any deep dependency change, propagate POSSIBLY_STALE to all observers, wait for 3.
|
|
36
|
+
* 3. When it's being accessed, recompute if any shallow dependency changed.
|
|
37
|
+
* if result changed: propagate STALE to all observers, that were POSSIBLY_STALE from the last step.
|
|
38
|
+
* go to step 2. either way
|
|
39
|
+
*
|
|
40
|
+
* If at any point it's outside batch and it isn't observed: reset everything and go to 1.
|
|
41
|
+
*/
|
|
42
|
+
export declare class ComputedValue<T> implements IObservable, IComputedValue<T>, IDerivation {
|
|
43
|
+
dependenciesState_: IDerivationState_;
|
|
44
|
+
observing_: IObservable[];
|
|
45
|
+
newObserving_: null;
|
|
46
|
+
isBeingObserved_: boolean;
|
|
47
|
+
isPendingUnobservation_: boolean;
|
|
48
|
+
observers_: Set<IDerivation>;
|
|
49
|
+
diffValue_: number;
|
|
50
|
+
runId_: number;
|
|
51
|
+
lastAccessedBy_: number;
|
|
52
|
+
lowestObserverState_: IDerivationState_;
|
|
53
|
+
unboundDepsCount_: number;
|
|
54
|
+
protected value_: T | undefined | CaughtException;
|
|
55
|
+
name_: string;
|
|
56
|
+
triggeredBy_?: string;
|
|
57
|
+
isComputing_: boolean;
|
|
58
|
+
isRunningSetter_: boolean;
|
|
59
|
+
derivation: () => T;
|
|
60
|
+
setter_?: (value: T) => void;
|
|
61
|
+
isTracing_: TraceMode;
|
|
62
|
+
scope_: Object | undefined;
|
|
63
|
+
private equals_;
|
|
64
|
+
private requiresReaction_;
|
|
65
|
+
keepAlive_: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Create a new computed value based on a function expression.
|
|
68
|
+
*
|
|
69
|
+
* The `name` property is for debug purposes only.
|
|
70
|
+
*
|
|
71
|
+
* The `equals` property specifies the comparer function to use to determine if a newly produced
|
|
72
|
+
* value differs from the previous value. Two comparers are provided in the library; `defaultComparer`
|
|
73
|
+
* compares based on identity comparison (===), and `structuralComparer` deeply compares the structure.
|
|
74
|
+
* Structural comparison can be convenient if you always produce a new aggregated object and
|
|
75
|
+
* don't want to notify observers if it is structurally the same.
|
|
76
|
+
* This is useful for working with vectors, mouse coordinates etc.
|
|
77
|
+
*/
|
|
78
|
+
constructor(options: IComputedValueOptions<T>);
|
|
79
|
+
onBecomeStale_(): void;
|
|
80
|
+
onBOL: Set<Lambda> | undefined;
|
|
81
|
+
onBUOL: Set<Lambda> | undefined;
|
|
82
|
+
onBO(): void;
|
|
83
|
+
onBUO(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Returns the current value of this computed value.
|
|
86
|
+
* Will evaluate its computation first if needed.
|
|
87
|
+
*/
|
|
88
|
+
get(): T;
|
|
89
|
+
set(value: T): void;
|
|
90
|
+
trackAndCompute(): boolean;
|
|
91
|
+
computeValue_(track: boolean): T | CaughtException;
|
|
92
|
+
suspend_(): void;
|
|
93
|
+
observe_(listener: (change: IComputedDidChange<T>) => void, fireImmediately?: boolean): Lambda;
|
|
94
|
+
warnAboutUntrackedRead_(): void;
|
|
95
|
+
toString(): string;
|
|
96
|
+
valueOf(): T;
|
|
97
|
+
[Symbol.toPrimitive](): T;
|
|
98
|
+
}
|
|
99
|
+
export declare const isComputedValue: (x: any) => x is ComputedValue<unknown>;
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { IAtom, IDepTreeNode, IObservable } 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
|
-
onBecomeStale_(): void;
|
|
31
|
-
isTracing_: TraceMode;
|
|
32
|
-
/**
|
|
33
|
-
* warn if the derivation has no dependencies after creation/update
|
|
34
|
-
*/
|
|
35
|
-
requiresObservable_?: boolean;
|
|
36
|
-
}
|
|
37
|
-
export declare class CaughtException {
|
|
38
|
-
cause: any;
|
|
39
|
-
constructor(cause: any);
|
|
40
|
-
}
|
|
41
|
-
export declare function isCaughtException(e: any): e is CaughtException;
|
|
42
|
-
/**
|
|
43
|
-
* Finds out whether any dependency of the derivation has actually changed.
|
|
44
|
-
* If dependenciesState is 1 then it will recalculate dependencies,
|
|
45
|
-
* if any dependency changed it will propagate it by changing dependenciesState to 2.
|
|
46
|
-
*
|
|
47
|
-
* By iterating over the dependencies in the same order that they were reported and
|
|
48
|
-
* stopping on the first change, all the recalculations are only called for ComputedValues
|
|
49
|
-
* that will be tracked by derivation. That is because we assume that if the first x
|
|
50
|
-
* dependencies of the derivation doesn't change then the derivation should run the same way
|
|
51
|
-
* up until accessing x-th dependency.
|
|
52
|
-
*/
|
|
53
|
-
export declare function shouldCompute(derivation: IDerivation): boolean;
|
|
54
|
-
export declare function isComputingDerivation(): boolean;
|
|
55
|
-
export declare function checkIfStateModificationsAreAllowed(atom: IAtom): void;
|
|
56
|
-
export declare function checkIfStateReadsAreAllowed(observable: IObservable): void;
|
|
57
|
-
/**
|
|
58
|
-
* Executes the provided function `f` and tracks which observables are being accessed.
|
|
59
|
-
* The tracking information is stored on the `derivation` object and the derivation is registered
|
|
60
|
-
* as observer of any of the accessed observables.
|
|
61
|
-
*/
|
|
62
|
-
export declare function trackDerivedFunction<T>(derivation: IDerivation, f: () => T, context: any): any;
|
|
63
|
-
export declare function clearObserving(derivation: IDerivation): void;
|
|
64
|
-
export declare function untracked<T>(action: () => T): T;
|
|
65
|
-
export declare function untrackedStart(): IDerivation | null;
|
|
66
|
-
export declare function untrackedEnd(prev: IDerivation | null): void;
|
|
67
|
-
export declare function allowStateReadsStart(allowStateReads: boolean): boolean;
|
|
68
|
-
export declare function allowStateReadsEnd(prev: boolean): void;
|
|
69
|
-
/**
|
|
70
|
-
* needed to keep `lowestObserverState` correct. when changing from (2 or 1) to 0
|
|
71
|
-
*
|
|
72
|
-
*/
|
|
73
|
-
export declare function changeDependenciesStateTo0(derivation: IDerivation): void;
|
|
1
|
+
import { IAtom, IDepTreeNode, IObservable } 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
|
+
onBecomeStale_(): void;
|
|
31
|
+
isTracing_: TraceMode;
|
|
32
|
+
/**
|
|
33
|
+
* warn if the derivation has no dependencies after creation/update
|
|
34
|
+
*/
|
|
35
|
+
requiresObservable_?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare class CaughtException {
|
|
38
|
+
cause: any;
|
|
39
|
+
constructor(cause: any);
|
|
40
|
+
}
|
|
41
|
+
export declare function isCaughtException(e: any): e is CaughtException;
|
|
42
|
+
/**
|
|
43
|
+
* Finds out whether any dependency of the derivation has actually changed.
|
|
44
|
+
* If dependenciesState is 1 then it will recalculate dependencies,
|
|
45
|
+
* if any dependency changed it will propagate it by changing dependenciesState to 2.
|
|
46
|
+
*
|
|
47
|
+
* By iterating over the dependencies in the same order that they were reported and
|
|
48
|
+
* stopping on the first change, all the recalculations are only called for ComputedValues
|
|
49
|
+
* that will be tracked by derivation. That is because we assume that if the first x
|
|
50
|
+
* dependencies of the derivation doesn't change then the derivation should run the same way
|
|
51
|
+
* up until accessing x-th dependency.
|
|
52
|
+
*/
|
|
53
|
+
export declare function shouldCompute(derivation: IDerivation): boolean;
|
|
54
|
+
export declare function isComputingDerivation(): boolean;
|
|
55
|
+
export declare function checkIfStateModificationsAreAllowed(atom: IAtom): void;
|
|
56
|
+
export declare function checkIfStateReadsAreAllowed(observable: IObservable): void;
|
|
57
|
+
/**
|
|
58
|
+
* Executes the provided function `f` and tracks which observables are being accessed.
|
|
59
|
+
* The tracking information is stored on the `derivation` object and the derivation is registered
|
|
60
|
+
* as observer of any of the accessed observables.
|
|
61
|
+
*/
|
|
62
|
+
export declare function trackDerivedFunction<T>(derivation: IDerivation, f: () => T, context: any): any;
|
|
63
|
+
export declare function clearObserving(derivation: IDerivation): void;
|
|
64
|
+
export declare function untracked<T>(action: () => T): T;
|
|
65
|
+
export declare function untrackedStart(): IDerivation | null;
|
|
66
|
+
export declare function untrackedEnd(prev: IDerivation | null): void;
|
|
67
|
+
export declare function allowStateReadsStart(allowStateReads: boolean): boolean;
|
|
68
|
+
export declare function allowStateReadsEnd(prev: boolean): void;
|
|
69
|
+
/**
|
|
70
|
+
* needed to keep `lowestObserverState` correct. when changing from (2 or 1) to 0
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
export declare function changeDependenciesStateTo0(derivation: IDerivation): void;
|