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.
Files changed (56) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +19 -10
  3. package/lib/api/action.d.ts +13 -13
  4. package/lib/api/actiondecorator.d.ts +27 -27
  5. package/lib/api/autorun.d.ts +24 -24
  6. package/lib/api/become-observed.d.ts +5 -5
  7. package/lib/api/computed.d.ts +14 -14
  8. package/lib/api/configure.d.ts +19 -19
  9. package/lib/api/decorate.d.ts +6 -6
  10. package/lib/api/extendobservable.d.ts +7 -7
  11. package/lib/api/extras.d.ts +10 -10
  12. package/lib/api/flow.d.ts +9 -9
  13. package/lib/api/intercept-read.d.ts +8 -8
  14. package/lib/api/intercept.d.ts +8 -8
  15. package/lib/api/iscomputed.d.ts +3 -3
  16. package/lib/api/isobservable.d.ts +2 -2
  17. package/lib/api/object-api.d.ts +34 -34
  18. package/lib/api/observable.d.ts +54 -54
  19. package/lib/api/observabledecorator.d.ts +6 -6
  20. package/lib/api/observe.d.ts +8 -8
  21. package/lib/api/tojs.d.ts +11 -11
  22. package/lib/api/trace.d.ts +3 -3
  23. package/lib/api/transaction.d.ts +8 -8
  24. package/lib/api/when.d.ts +15 -15
  25. package/lib/core/action.d.ts +22 -22
  26. package/lib/core/atom.d.ts +40 -40
  27. package/lib/core/computedvalue.d.ts +93 -93
  28. package/lib/core/derivation.d.ts +74 -74
  29. package/lib/core/globalstate.d.ts +106 -106
  30. package/lib/core/observable.d.ts +44 -44
  31. package/lib/core/reaction.d.ts +63 -63
  32. package/lib/core/spy.d.ts +6 -6
  33. package/lib/index.js +7 -0
  34. package/lib/internal.d.ts +44 -44
  35. package/lib/mobx.d.ts +19 -19
  36. package/lib/mobx.es6.js +4436 -4293
  37. package/lib/mobx.js +4520 -4387
  38. package/lib/mobx.min.js +15 -1
  39. package/lib/mobx.module.js +4535 -4388
  40. package/lib/mobx.umd.js +4536 -4389
  41. package/lib/mobx.umd.min.js +15 -1
  42. package/lib/types/intercept-utils.d.ts +9 -9
  43. package/lib/types/listen-utils.d.ts +8 -8
  44. package/lib/types/modifiers.d.ts +7 -7
  45. package/lib/types/observablearray.d.ts +78 -78
  46. package/lib/types/observablemap.d.ts +83 -83
  47. package/lib/types/observableobject.d.ts +65 -65
  48. package/lib/types/observableset.d.ts +49 -49
  49. package/lib/types/observablevalue.d.ts +37 -37
  50. package/lib/types/type-utils.d.ts +4 -4
  51. package/lib/utils/comparer.d.ts +14 -14
  52. package/lib/utils/decorators2.d.ts +7 -7
  53. package/lib/utils/eq.d.ts +1 -1
  54. package/lib/utils/iterable.d.ts +5 -5
  55. package/lib/utils/utils.d.ts +42 -43
  56. package/package.json +3 -13
@@ -1,54 +1,54 @@
1
- import { IEqualsComparer, IObservableDecorator, IEnhancer, IObservableArray, ObservableMap, IObservableObject, IObservableValue, IObservableSetInitialValues, ObservableSet, IObservableMapInitialValues } from "../internal";
2
- export declare type CreateObservableOptions = {
3
- name?: string;
4
- equals?: IEqualsComparer<any>;
5
- deep?: boolean;
6
- defaultDecorator?: IObservableDecorator;
7
- };
8
- export declare const defaultCreateObservableOptions: CreateObservableOptions;
9
- export declare const shallowCreateObservableOptions: {
10
- deep: boolean;
11
- name: undefined;
12
- defaultDecorator: undefined;
13
- };
14
- export declare function asCreateObservableOptions(thing: any): CreateObservableOptions;
15
- export declare const deepDecorator: IObservableDecorator;
16
- export declare const refDecorator: IObservableDecorator;
17
- export interface IObservableFactory {
18
- (value: number | string | null | undefined | boolean): never;
19
- (target: Object, key: string | symbol, baseDescriptor?: PropertyDescriptor): any;
20
- <T = any>(value: T[], options?: CreateObservableOptions): IObservableArray<T>;
21
- <T = any>(value: Set<T>, options?: CreateObservableOptions): ObservableSet<T>;
22
- <K = any, V = any>(value: Map<K, V>, options?: CreateObservableOptions): ObservableMap<K, V>;
23
- <T extends Object>(value: T, decorators?: {
24
- [K in keyof T]?: Function;
25
- }, options?: CreateObservableOptions): T & IObservableObject;
26
- }
27
- export interface IObservableFactories {
28
- box<T = any>(value?: T, options?: CreateObservableOptions): IObservableValue<T>;
29
- shallowBox<T = any>(value?: T, options?: CreateObservableOptions): IObservableValue<T>;
30
- array<T = any>(initialValues?: T[], options?: CreateObservableOptions): IObservableArray<T>;
31
- shallowArray<T = any>(initialValues?: T[], options?: CreateObservableOptions): IObservableArray<T>;
32
- set<T = any>(initialValues?: IObservableSetInitialValues<T>, options?: CreateObservableOptions): ObservableSet<T>;
33
- map<K = any, V = any>(initialValues?: IObservableMapInitialValues<K, V>, options?: CreateObservableOptions): ObservableMap<K, V>;
34
- shallowMap<K = any, V = any>(initialValues?: IObservableMapInitialValues<K, V>, options?: CreateObservableOptions): ObservableMap<K, V>;
35
- object<T = any>(props: T, decorators?: {
36
- [K in keyof T]?: Function;
37
- }, options?: CreateObservableOptions): T & IObservableObject;
38
- shallowObject<T = any>(props: T, decorators?: {
39
- [K in keyof T]?: Function;
40
- }, options?: CreateObservableOptions): T & IObservableObject;
41
- /**
42
- * Decorator that creates an observable that only observes the references, but doesn't try to turn the assigned value into an observable.ts.
43
- */
44
- ref: IObservableDecorator;
45
- /**
46
- * Decorator that creates an observable converts its value (objects, maps or arrays) into a shallow observable structure
47
- */
48
- shallow: IObservableDecorator;
49
- deep: IObservableDecorator;
50
- struct: IObservableDecorator;
51
- }
52
- export declare const observable: IObservableFactory & IObservableFactories & {
53
- enhancer: IEnhancer<any>;
54
- };
1
+ import { IEqualsComparer, IObservableDecorator, IEnhancer, IObservableArray, ObservableMap, IObservableObject, IObservableValue, IObservableSetInitialValues, ObservableSet, IObservableMapInitialValues } from "../internal";
2
+ export declare type CreateObservableOptions = {
3
+ name?: string;
4
+ equals?: IEqualsComparer<any>;
5
+ deep?: boolean;
6
+ defaultDecorator?: IObservableDecorator;
7
+ };
8
+ export declare const defaultCreateObservableOptions: CreateObservableOptions;
9
+ export declare const shallowCreateObservableOptions: {
10
+ deep: boolean;
11
+ name: undefined;
12
+ defaultDecorator: undefined;
13
+ };
14
+ export declare function asCreateObservableOptions(thing: any): CreateObservableOptions;
15
+ export declare const deepDecorator: IObservableDecorator;
16
+ export declare const refDecorator: IObservableDecorator;
17
+ export interface IObservableFactory {
18
+ (value: number | string | null | undefined | boolean): never;
19
+ (target: Object, key: string | symbol, baseDescriptor?: PropertyDescriptor): any;
20
+ <T = any>(value: T[], options?: CreateObservableOptions): IObservableArray<T>;
21
+ <T = any>(value: Set<T>, options?: CreateObservableOptions): ObservableSet<T>;
22
+ <K = any, V = any>(value: Map<K, V>, options?: CreateObservableOptions): ObservableMap<K, V>;
23
+ <T extends Object>(value: T, decorators?: {
24
+ [K in keyof T]?: Function;
25
+ }, options?: CreateObservableOptions): T & IObservableObject;
26
+ }
27
+ export interface IObservableFactories {
28
+ box: <T = any>(value?: T, options?: CreateObservableOptions) => IObservableValue<T>;
29
+ shallowBox: <T = any>(value?: T, options?: CreateObservableOptions) => IObservableValue<T>;
30
+ array: <T = any>(initialValues?: T[], options?: CreateObservableOptions) => IObservableArray<T>;
31
+ shallowArray: <T = any>(initialValues?: T[], options?: CreateObservableOptions) => IObservableArray<T>;
32
+ set: <T = any>(initialValues?: IObservableSetInitialValues<T>, options?: CreateObservableOptions) => ObservableSet<T>;
33
+ map: <K = any, V = any>(initialValues?: IObservableMapInitialValues<K, V>, options?: CreateObservableOptions) => ObservableMap<K, V>;
34
+ shallowMap: <K = any, V = any>(initialValues?: IObservableMapInitialValues<K, V>, options?: CreateObservableOptions) => ObservableMap<K, V>;
35
+ object: <T = any>(props: T, decorators?: {
36
+ [K in keyof T]?: Function;
37
+ }, options?: CreateObservableOptions) => T & IObservableObject;
38
+ shallowObject: <T = any>(props: T, decorators?: {
39
+ [K in keyof T]?: Function;
40
+ }, options?: CreateObservableOptions) => T & IObservableObject;
41
+ /**
42
+ * Decorator that creates an observable that only observes the references, but doesn't try to turn the assigned value into an observable.ts.
43
+ */
44
+ ref: IObservableDecorator;
45
+ /**
46
+ * Decorator that creates an observable converts its value (objects, maps or arrays) into a shallow observable structure
47
+ */
48
+ shallow: IObservableDecorator;
49
+ deep: IObservableDecorator;
50
+ struct: IObservableDecorator;
51
+ }
52
+ export declare const observable: IObservableFactory & IObservableFactories & {
53
+ enhancer: IEnhancer<any>;
54
+ };
@@ -1,6 +1,6 @@
1
- import { IEnhancer } from "../internal";
2
- export declare type IObservableDecorator = {
3
- (target: Object, property: string | symbol, descriptor?: PropertyDescriptor): void;
4
- enhancer: IEnhancer<any>;
5
- };
6
- export declare function createDecoratorForEnhancer(enhancer: IEnhancer<any>): IObservableDecorator;
1
+ import { IEnhancer } from "../internal";
2
+ export declare type IObservableDecorator = {
3
+ (target: Object, property: string | symbol, descriptor?: PropertyDescriptor): void;
4
+ enhancer: IEnhancer<any>;
5
+ };
6
+ export declare function createDecoratorForEnhancer(enhancer: IEnhancer<any>): IObservableDecorator;
@@ -1,8 +1,8 @@
1
- import { IObservableArray, IArrayChange, IArraySplice, IObservableValue, IComputedValue, IValueDidChange, Lambda, ObservableSet, ISetDidChange, ObservableMap, IMapDidChange, IObjectDidChange } from "../internal";
2
- export declare function observe<T>(value: IObservableValue<T> | IComputedValue<T>, listener: (change: IValueDidChange<T>) => void, fireImmediately?: boolean): Lambda;
3
- export declare function observe<T>(observableArray: IObservableArray<T>, listener: (change: IArrayChange<T> | IArraySplice<T>) => void, fireImmediately?: boolean): Lambda;
4
- export declare function observe<V>(observableMap: ObservableSet<V>, listener: (change: ISetDidChange<V>) => void, fireImmediately?: boolean): Lambda;
5
- export declare function observe<K, V>(observableMap: ObservableMap<K, V>, listener: (change: IMapDidChange<K, V>) => void, fireImmediately?: boolean): Lambda;
6
- export declare function observe<K, V>(observableMap: ObservableMap<K, V>, property: K, listener: (change: IValueDidChange<V>) => void, fireImmediately?: boolean): Lambda;
7
- export declare function observe(object: Object, listener: (change: IObjectDidChange) => void, fireImmediately?: boolean): Lambda;
8
- export declare function observe<T, K extends keyof T>(object: T, property: K, listener: (change: IValueDidChange<T[K]>) => void, fireImmediately?: boolean): Lambda;
1
+ import { IObservableArray, IArrayChange, IArraySplice, IObservableValue, IComputedValue, IValueDidChange, Lambda, ObservableSet, ISetDidChange, ObservableMap, IMapDidChange, IObjectDidChange } from "../internal";
2
+ export declare function observe<T>(value: IObservableValue<T> | IComputedValue<T>, listener: (change: IValueDidChange<T>) => void, fireImmediately?: boolean): Lambda;
3
+ export declare function observe<T>(observableArray: IObservableArray<T>, listener: (change: IArrayChange<T> | IArraySplice<T>) => void, fireImmediately?: boolean): Lambda;
4
+ export declare function observe<V>(observableMap: ObservableSet<V>, listener: (change: ISetDidChange<V>) => void, fireImmediately?: boolean): Lambda;
5
+ export declare function observe<K, V>(observableMap: ObservableMap<K, V>, listener: (change: IMapDidChange<K, V>) => void, fireImmediately?: boolean): Lambda;
6
+ export declare function observe<K, V>(observableMap: ObservableMap<K, V>, property: K, listener: (change: IValueDidChange<V>) => void, fireImmediately?: boolean): Lambda;
7
+ export declare function observe(object: Object, listener: (change: IObjectDidChange) => void, fireImmediately?: boolean): Lambda;
8
+ export declare function observe<T, K extends keyof T>(object: T, property: K, listener: (change: IValueDidChange<T[K]>) => void, fireImmediately?: boolean): Lambda;
package/lib/api/tojs.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- export declare type ToJSOptions = {
2
- detectCycles?: boolean;
3
- exportMapsAsObjects?: boolean;
4
- recurseEverything?: boolean;
5
- };
6
- /**
7
- * Basically, a deep clone, so that no reactive property will exist anymore.
8
- */
9
- export declare function toJS<T>(source: T, options?: ToJSOptions): T;
10
- export declare function toJS(source: any, options?: ToJSOptions): any;
11
- export declare function toJS(source: any, options: ToJSOptions): any;
1
+ export declare type ToJSOptions = {
2
+ detectCycles?: boolean;
3
+ exportMapsAsObjects?: boolean;
4
+ recurseEverything?: boolean;
5
+ };
6
+ /**
7
+ * Basically, a deep clone, so that no reactive property will exist anymore.
8
+ */
9
+ export declare function toJS<T>(source: T, options?: ToJSOptions): T;
10
+ export declare function toJS(source: any, options?: ToJSOptions): any;
11
+ export declare function toJS(source: any, options: ToJSOptions): any;
@@ -1,3 +1,3 @@
1
- export declare function trace(thing?: any, prop?: string, enterBreakPoint?: boolean): void;
2
- export declare function trace(thing?: any, enterBreakPoint?: boolean): void;
3
- export declare function trace(enterBreakPoint?: boolean): void;
1
+ export declare function trace(thing?: any, prop?: string, enterBreakPoint?: boolean): void;
2
+ export declare function trace(thing?: any, enterBreakPoint?: boolean): void;
3
+ export declare function trace(enterBreakPoint?: boolean): void;
@@ -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/lib/api/when.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import { Lambda, IReactionDisposer } from "../internal";
2
- export interface IWhenOptions {
3
- name?: string;
4
- timeout?: number;
5
- /**
6
- * Experimental.
7
- * Warns if the view doesn't track observables
8
- */
9
- requiresObservable?: boolean;
10
- onError?: (error: any) => void;
11
- }
12
- export declare function when(predicate: () => boolean, opts?: IWhenOptions): Promise<void> & {
13
- cancel(): void;
14
- };
15
- export declare function when(predicate: () => boolean, effect: Lambda, opts?: IWhenOptions): IReactionDisposer;
1
+ import { Lambda, IReactionDisposer } from "../internal";
2
+ export interface IWhenOptions {
3
+ name?: string;
4
+ timeout?: number;
5
+ /**
6
+ * Experimental.
7
+ * Warns if the view doesn't track observables
8
+ */
9
+ requiresObservable?: boolean;
10
+ onError?: (error: any) => void;
11
+ }
12
+ export declare function when(predicate: () => boolean, opts?: IWhenOptions): Promise<void> & {
13
+ cancel(): void;
14
+ };
15
+ export declare function when(predicate: () => boolean, effect: Lambda, opts?: IWhenOptions): IReactionDisposer;
@@ -1,22 +1,22 @@
1
- import { IDerivation } from "../internal";
2
- export interface IAction {
3
- isMobxAction: boolean;
4
- }
5
- export declare function createAction(actionName: string, fn: Function): Function & IAction;
6
- export declare function executeAction(actionName: string, fn: Function, scope?: any, args?: IArguments): any;
7
- export interface IActionRunInfo {
8
- prevDerivation: IDerivation | null;
9
- prevAllowStateChanges: boolean;
10
- prevAllowStateReads: boolean;
11
- notifySpy: boolean;
12
- startTime: number;
13
- error?: any;
14
- parentActionId: number;
15
- actionId: number;
16
- }
17
- export declare function _startAction(actionName: string, scope: any, args?: IArguments): IActionRunInfo;
18
- export declare function _endAction(runInfo: IActionRunInfo): void;
19
- export declare function allowStateChanges<T>(allowStateChanges: boolean, func: () => T): T;
20
- export declare function allowStateChangesStart(allowStateChanges: boolean): boolean;
21
- export declare function allowStateChangesEnd(prev: boolean): void;
22
- export declare function allowStateChangesInsideComputed<T>(func: () => T): T;
1
+ import { IDerivation } from "../internal";
2
+ export interface IAction {
3
+ isMobxAction: boolean;
4
+ }
5
+ export declare function createAction(actionName: string, fn: Function): Function & IAction;
6
+ export declare function executeAction(actionName: string, fn: Function, scope?: any, args?: IArguments): any;
7
+ export interface IActionRunInfo {
8
+ prevDerivation: IDerivation | null;
9
+ prevAllowStateChanges: boolean;
10
+ prevAllowStateReads: boolean;
11
+ notifySpy: boolean;
12
+ startTime: number;
13
+ error?: any;
14
+ parentActionId: number;
15
+ actionId: number;
16
+ }
17
+ export declare function _startAction(actionName: string, scope: any, args?: IArguments): IActionRunInfo;
18
+ export declare function _endAction(runInfo: IActionRunInfo): void;
19
+ export declare function allowStateChanges<T>(allowStateChanges: boolean, func: () => T): T;
20
+ export declare function allowStateChangesStart(allowStateChanges: boolean): boolean;
21
+ export declare function allowStateChangesEnd(prev: boolean): void;
22
+ export declare function allowStateChangesInsideComputed<T>(func: () => T): T;
@@ -1,40 +1,40 @@
1
- import { IObservable, IDerivationState } from "../internal";
2
- export interface IAtom extends IObservable {
3
- reportObserved(): any;
4
- reportChanged(): any;
5
- }
6
- /**
7
- * Anything that can be used to _store_ state is an Atom in mobx. Atoms have two important jobs
8
- *
9
- * 1) detect when they are being _used_ and report this (using reportObserved). This allows mobx to make the connection between running functions and the data they used
10
- * 2) they should notify mobx whenever they have _changed_. This way mobx can re-run any functions (derivations) that are using this atom.
11
- */
12
- export declare class Atom implements IAtom {
13
- name: string;
14
- isPendingUnobservation: boolean;
15
- isBeingObserved: boolean;
16
- observers: never[];
17
- observersIndexes: {};
18
- diffValue: number;
19
- lastAccessedBy: number;
20
- lowestObserverState: IDerivationState;
21
- /**
22
- * Create a new atom. For debugging purposes it is recommended to give it a name.
23
- * The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
24
- */
25
- constructor(name?: string);
26
- onBecomeUnobserved(): void;
27
- onBecomeObserved(): void;
28
- /**
29
- * Invoke this method to notify mobx that your atom has been used somehow.
30
- * Returns true if there is currently a reactive context.
31
- */
32
- reportObserved(): boolean;
33
- /**
34
- * Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
35
- */
36
- reportChanged(): void;
37
- toString(): string;
38
- }
39
- export declare const isAtom: (x: any) => x is Atom;
40
- export declare function createAtom(name: string, onBecomeObservedHandler?: () => void, onBecomeUnobservedHandler?: () => void): IAtom;
1
+ import { IObservable, IDerivationState } from "../internal";
2
+ export interface IAtom extends IObservable {
3
+ reportObserved(): any;
4
+ reportChanged(): any;
5
+ }
6
+ /**
7
+ * Anything that can be used to _store_ state is an Atom in mobx. Atoms have two important jobs
8
+ *
9
+ * 1) detect when they are being _used_ and report this (using reportObserved). This allows mobx to make the connection between running functions and the data they used
10
+ * 2) they should notify mobx whenever they have _changed_. This way mobx can re-run any functions (derivations) that are using this atom.
11
+ */
12
+ export declare class Atom implements IAtom {
13
+ name: string;
14
+ isPendingUnobservation: boolean;
15
+ isBeingObserved: boolean;
16
+ observers: never[];
17
+ observersIndexes: {};
18
+ diffValue: number;
19
+ lastAccessedBy: number;
20
+ lowestObserverState: IDerivationState;
21
+ /**
22
+ * Create a new atom. For debugging purposes it is recommended to give it a name.
23
+ * The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
24
+ */
25
+ constructor(name?: string);
26
+ onBecomeUnobserved(): void;
27
+ onBecomeObserved(): void;
28
+ /**
29
+ * Invoke this method to notify mobx that your atom has been used somehow.
30
+ * Returns true if there is currently a reactive context.
31
+ */
32
+ reportObserved(): boolean;
33
+ /**
34
+ * Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
35
+ */
36
+ reportChanged(): void;
37
+ toString(): string;
38
+ }
39
+ export declare const isAtom: (x: any) => x is Atom;
40
+ export declare function createAtom(name: string, onBecomeObservedHandler?: () => void, onBecomeUnobservedHandler?: () => void): IAtom;
@@ -1,93 +1,93 @@
1
- import { IObservable, IValueDidChange, Lambda, IEqualsComparer, IDerivation, IDerivationState, CaughtException, TraceMode } from "../internal";
2
- export interface IComputedValue<T> {
3
- get(): T;
4
- set(value: T): void;
5
- observe(listener: (change: IValueDidChange<T>) => void, fireImmediately?: boolean): Lambda;
6
- }
7
- export interface IComputedValueOptions<T> {
8
- get?: () => T;
9
- set?: (value: T) => void;
10
- name?: string;
11
- equals?: IEqualsComparer<T>;
12
- context?: any;
13
- requiresReaction?: boolean;
14
- keepAlive?: boolean;
15
- }
16
- /**
17
- * A node in the state dependency root that observes other nodes, and can be observed itself.
18
- *
19
- * ComputedValue will remember the result of the computation for the duration of the batch, or
20
- * while being observed.
21
- *
22
- * During this time it will recompute only when one of its direct dependencies changed,
23
- * but only when it is being accessed with `ComputedValue.get()`.
24
- *
25
- * Implementation description:
26
- * 1. First time it's being accessed it will compute and remember result
27
- * give back remembered result until 2. happens
28
- * 2. First time any deep dependency change, propagate POSSIBLY_STALE to all observers, wait for 3.
29
- * 3. When it's being accessed, recompute if any shallow dependency changed.
30
- * if result changed: propagate STALE to all observers, that were POSSIBLY_STALE from the last step.
31
- * go to step 2. either way
32
- *
33
- * If at any point it's outside batch and it isn't observed: reset everything and go to 1.
34
- */
35
- export declare class ComputedValue<T> implements IObservable, IComputedValue<T>, IDerivation {
36
- dependenciesState: IDerivationState;
37
- observing: IObservable[];
38
- newObserving: null;
39
- isBeingObserved: boolean;
40
- isPendingUnobservation: boolean;
41
- observers: never[];
42
- observersIndexes: {};
43
- diffValue: number;
44
- runId: number;
45
- lastAccessedBy: number;
46
- lowestObserverState: IDerivationState;
47
- unboundDepsCount: number;
48
- __mapid: string;
49
- protected value: T | undefined | CaughtException;
50
- name: string;
51
- triggeredBy?: string;
52
- isComputing: boolean;
53
- isRunningSetter: boolean;
54
- derivation: () => T;
55
- setter?: (value: T) => void;
56
- isTracing: TraceMode;
57
- scope: Object | undefined;
58
- private equals;
59
- private requiresReaction;
60
- private keepAlive;
61
- /**
62
- * Create a new computed value based on a function expression.
63
- *
64
- * The `name` property is for debug purposes only.
65
- *
66
- * The `equals` property specifies the comparer function to use to determine if a newly produced
67
- * value differs from the previous value. Two comparers are provided in the library; `defaultComparer`
68
- * compares based on identity comparison (===), and `structualComparer` deeply compares the structure.
69
- * Structural comparison can be convenient if you always produce a new aggregated object and
70
- * don't want to notify observers if it is structurally the same.
71
- * This is useful for working with vectors, mouse coordinates etc.
72
- */
73
- constructor(options: IComputedValueOptions<T>);
74
- onBecomeStale(): void;
75
- onBecomeUnobserved(): void;
76
- onBecomeObserved(): void;
77
- /**
78
- * Returns the current value of this computed value.
79
- * Will evaluate its computation first if needed.
80
- */
81
- get(): T;
82
- peek(): T;
83
- set(value: T): void;
84
- private trackAndCompute;
85
- computeValue(track: boolean): T | CaughtException;
86
- suspend(): void;
87
- observe(listener: (change: IValueDidChange<T>) => void, fireImmediately?: boolean): Lambda;
88
- warnAboutUntrackedRead(): void;
89
- toJSON(): T;
90
- toString(): string;
91
- valueOf(): T;
92
- }
93
- export declare const isComputedValue: (x: any) => x is ComputedValue<unknown>;
1
+ import { IObservable, IValueDidChange, Lambda, IEqualsComparer, IDerivation, IDerivationState, CaughtException, TraceMode } from "../internal";
2
+ export interface IComputedValue<T> {
3
+ get(): T;
4
+ set(value: T): void;
5
+ observe(listener: (change: IValueDidChange<T>) => void, fireImmediately?: boolean): Lambda;
6
+ }
7
+ export interface IComputedValueOptions<T> {
8
+ get?: () => T;
9
+ set?: (value: T) => void;
10
+ name?: string;
11
+ equals?: IEqualsComparer<T>;
12
+ context?: any;
13
+ requiresReaction?: boolean;
14
+ keepAlive?: boolean;
15
+ }
16
+ /**
17
+ * A node in the state dependency root that observes other nodes, and can be observed itself.
18
+ *
19
+ * ComputedValue will remember the result of the computation for the duration of the batch, or
20
+ * while being observed.
21
+ *
22
+ * During this time it will recompute only when one of its direct dependencies changed,
23
+ * but only when it is being accessed with `ComputedValue.get()`.
24
+ *
25
+ * Implementation description:
26
+ * 1. First time it's being accessed it will compute and remember result
27
+ * give back remembered result until 2. happens
28
+ * 2. First time any deep dependency change, propagate POSSIBLY_STALE to all observers, wait for 3.
29
+ * 3. When it's being accessed, recompute if any shallow dependency changed.
30
+ * if result changed: propagate STALE to all observers, that were POSSIBLY_STALE from the last step.
31
+ * go to step 2. either way
32
+ *
33
+ * If at any point it's outside batch and it isn't observed: reset everything and go to 1.
34
+ */
35
+ export declare class ComputedValue<T> implements IObservable, IComputedValue<T>, IDerivation {
36
+ dependenciesState: IDerivationState;
37
+ observing: IObservable[];
38
+ newObserving: null;
39
+ isBeingObserved: boolean;
40
+ isPendingUnobservation: boolean;
41
+ observers: never[];
42
+ observersIndexes: {};
43
+ diffValue: number;
44
+ runId: number;
45
+ lastAccessedBy: number;
46
+ lowestObserverState: IDerivationState;
47
+ unboundDepsCount: number;
48
+ __mapid: string;
49
+ protected value: T | undefined | CaughtException;
50
+ name: string;
51
+ triggeredBy?: string;
52
+ isComputing: boolean;
53
+ isRunningSetter: boolean;
54
+ derivation: () => T;
55
+ setter?: (value: T) => void;
56
+ isTracing: TraceMode;
57
+ scope: Object | undefined;
58
+ private equals;
59
+ private requiresReaction;
60
+ private keepAlive;
61
+ /**
62
+ * Create a new computed value based on a function expression.
63
+ *
64
+ * The `name` property is for debug purposes only.
65
+ *
66
+ * The `equals` property specifies the comparer function to use to determine if a newly produced
67
+ * value differs from the previous value. Two comparers are provided in the library; `defaultComparer`
68
+ * compares based on identity comparison (===), and `structualComparer` deeply compares the structure.
69
+ * Structural comparison can be convenient if you always produce a new aggregated object and
70
+ * don't want to notify observers if it is structurally the same.
71
+ * This is useful for working with vectors, mouse coordinates etc.
72
+ */
73
+ constructor(options: IComputedValueOptions<T>);
74
+ onBecomeStale(): void;
75
+ onBecomeUnobserved(): void;
76
+ onBecomeObserved(): void;
77
+ /**
78
+ * Returns the current value of this computed value.
79
+ * Will evaluate its computation first if needed.
80
+ */
81
+ get(): T;
82
+ peek(): T;
83
+ set(value: T): void;
84
+ private trackAndCompute;
85
+ computeValue(track: boolean): T | CaughtException;
86
+ suspend(): void;
87
+ observe(listener: (change: IValueDidChange<T>) => void, fireImmediately?: boolean): Lambda;
88
+ warnAboutUntrackedRead(): void;
89
+ toJSON(): T;
90
+ toString(): string;
91
+ valueOf(): T;
92
+ }
93
+ export declare const isComputedValue: (x: any) => x is ComputedValue<unknown>;