@zedux/atoms
Version:
A Molecular State Engine for React
91 lines (90 loc) • 3.58 kB
TypeScript
import { Dispatchable, RecursivePartial, Settable } from '@zedux/core';
import { AtomGenerics, AtomGenericsToAtomApiGenerics, Cleanup, DependentEdge, EvaluationReason, EvaluationSourceType, ExportsInfusedSetter, LifecycleStatus, PromiseStatus } from '../../types/index';
import { InjectorDescriptor } from '../../utils/types';
import { Ecosystem } from '../Ecosystem';
import { AtomApi } from '../AtomApi';
import { AtomInstanceBase } from './AtomInstanceBase';
import { AtomTemplateBase } from '../templates/AtomTemplateBase';
declare const StoreState = 1;
declare const RawState = 2;
export declare class AtomInstance<G extends AtomGenerics, AtomTemplateType extends AtomTemplateBase<G, AtomInstance<G, AtomTemplateType>> = AtomTemplateBase<G, AtomInstance<G, any>>> extends AtomInstanceBase<G['State'], AtomTemplateType> {
readonly ecosystem: Ecosystem;
readonly template: AtomTemplateType;
readonly id: string;
readonly params: G['Params'];
status: LifecycleStatus;
api?: AtomApi<AtomGenericsToAtomApiGenerics<G>>;
exports: G['Exports'];
nextReasons: EvaluationReason[];
prevReasons?: EvaluationReason[];
promise: G['Promise'];
store: G['Store'];
_cancelDestruction?: Cleanup;
_createdAt: number;
_injectors?: InjectorDescriptor[];
_isEvaluating?: boolean;
_lastEdge?: WeakRef<DependentEdge>;
_nextInjectors?: InjectorDescriptor[];
_promiseError?: Error;
_promiseStatus?: PromiseStatus;
_stateType?: typeof StoreState | typeof RawState;
private _bufferedUpdate?;
private _subscription?;
constructor(ecosystem: Ecosystem, template: AtomTemplateType, id: string, params: G['Params']);
/**
* Detach this atom instance from the ecosystem and clean up all graph edges
* and other subscriptions/effects created by this atom instance.
*
* Destruction will bail out if this atom instance still has dependents. Pass
* `true` to force-destroy the atom instance anyway.
*/
destroy(force?: boolean): void;
/**
* An alias for `.store.dispatch()`
*/
dispatch: (action: Dispatchable) => any;
/**
* An alias for `instance.store.getState()`. Returns the current state of this
* atom instance's store.
*/
getState(): G['State'];
/**
* Force this atom instance to reevaluate.
*/
invalidate(operation?: string, sourceType?: EvaluationSourceType): void;
/**
* An alias for `.store.setState()`
*/
setState: (settable: Settable<G['State']>, meta?: any) => G['State'];
/**
* An alias for `.store.setStateDeep()`
*/
setStateDeep: (settable: Settable<RecursivePartial<G['State']>, G['State']>, meta?: any) => G['State'];
_set?: ExportsInfusedSetter<G['State'], G['Exports']>;
get _infusedSetter(): any;
_init(): void;
/**
* When a standard atom instance's refCount hits 0 and a ttl is set, we set a
* timeout to destroy this atom instance.
*/
_scheduleDestruction(): void;
_scheduleEvaluation: (reason: EvaluationReason, shouldSetTimeout?: boolean | undefined) => void;
private evaluationTask;
private _doEvaluate;
/**
* A standard atom's value can be one of:
*
* - A raw value
* - A Zedux store
* - A function that returns a raw value
* - A function that returns a Zedux store
* - A function that returns an AtomApi
*/
private _evaluate;
private _evaluationTask;
private _getTtl;
private _handleStateChange;
private _setStatus;
private _setPromise;
}
export {};