UNPKG

mobx

Version:

Simple, scalable state management.

38 lines (37 loc) 1.46 kB
import { IDerivationState, IObservable } from "../internal"; import { Lambda } from "../utils/utils"; export declare const $mobx: unique symbol; export interface IAtom extends IObservable { reportObserved(): any; reportChanged(): any; } export declare class Atom implements IAtom { name: string; isPendingUnobservation: boolean; isBeingObserved: boolean; observers: Set<any>; diffValue: number; lastAccessedBy: number; lowestObserverState: IDerivationState; /** * Create a new atom. For debugging purposes it is recommended to give it a name. * The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management. */ constructor(name?: string); onBecomeObservedListeners: Set<Lambda> | undefined; onBecomeUnobservedListeners: Set<Lambda> | undefined; onBecomeObserved(): void; onBecomeUnobserved(): void; /** * Invoke this method to notify mobx that your atom has been used somehow. * Returns true if there is currently a reactive context. */ reportObserved(): boolean; /** * Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate. */ reportChanged(): void; toString(): string; } export declare const isAtom: (x: any) => x is Atom; export declare function createAtom(name: string, onBecomeObservedHandler?: () => void, onBecomeUnobservedHandler?: () => void): IAtom;