mobx
Version:
Simple, scalable state management.
54 lines (53 loc) • 2.62 kB
TypeScript
import { Lambda, IDerivation, IDerivationState_ } from "../internal";
export interface IDepTreeNode {
name_: string;
observing_?: IObservable[];
}
export interface IObservable extends IDepTreeNode {
diffValue: number;
/**
* Id of the derivation *run* that last accessed this observable.
* If this id equals the *run* id of the current derivation,
* the dependency is already established
*/
lastAccessedBy_: number;
isBeingObserved: boolean;
lowestObserverState_: IDerivationState_;
isPendingUnobservation: boolean;
observers_: Set<IDerivation> | null;
onBUO(): void;
onBO(): void;
onBUOL: Set<Lambda> | undefined;
onBOL: Set<Lambda> | undefined;
}
export declare function hasObservers(observable: IObservable): boolean;
export declare function getObservers(observable: IObservable): Set<IDerivation>;
export declare function addObserver(observable: IObservable, node: IDerivation): void;
export declare function removeObserver(observable: IObservable, node: IDerivation): void;
export declare function queueForUnobservation(observable: IObservable): void;
/**
* Batch starts a transaction, at least for purposes of memoizing ComputedValues when nothing else does.
* During a batch `onBecomeUnobserved` will be called at most once per observable.
* Avoids unnecessary recalculations.
*/
export declare function startBatch(): void;
export declare function endBatch(): void;
/**
* Marks an observable as observed, cascading into the dependencies of a ComputedValue.
* Unobservation already cascades (`suspend_` -> `clearObserving`), observation normally
* only does so by accident: a newly observed computed usually recomputes and re-reports
* its dependencies. When it serves a cached value instead nothing re-reports them, so the
* transition has to be propagated by hand. See #4547.
*/
export declare function markObserved(observable: IObservable): void;
export declare function reportObserved(observable: IObservable): boolean;
/**
* NOTE: current propagation mechanism will in case of self reruning autoruns behave unexpectedly
* It will propagate changes to observers from previous run
* It's hard or maybe impossible (with reasonable perf) to get it right with current approach
* Hopefully self reruning autoruns aren't a feature people should depend on
* Also most basic use cases should be ok
*/
export declare function propagateChanged(observable: IObservable): void;
export declare function propagateChangeConfirmed(observable: IObservable): void;
export declare function propagateMaybeChanged(observable: IObservable): void;