@zedux/atoms
Version:
A Molecular State Engine for React
32 lines (31 loc) • 1.59 kB
TypeScript
import { AnyAtomInstance, AnyAtomTemplate, AtomInstanceType, AtomParamsType, InjectAtomInstanceConfig, ParamlessTemplate } from '../types/index.js';
/**
* injectAtomInstance
*
* Creates an atom instance for the passed atom based on the passed params. If
* an instance has already been created for the passed params, reuses the
* existing instance.
*
* Registers a static graph dependency on the atom instance. This means atoms
* that use this injector will *not* reevaluate when this atom instance's state
* changes.
*
* Pass false as the 4th param to prevent this graph dependency from being
* registered. Useful when you need to control the graph dependency manually.
* `injectAtomSelector` does this internally.
*
* @param atom The atom to instantiate or reuse an instantiation of.
* @param params The params for generating the instance's key.
* @param operation The operation name (e.g. name of the injector function)
* that's triggering this graph dependency. If you're using this injector
* directly in an atom, it's fine to omit this parameter.
* @returns An atom instance, keyed based on the passed params.
*/
export declare const injectAtomInstance: {
<A extends AnyAtomTemplate>(template: A, params: AtomParamsType<A>, config?: InjectAtomInstanceConfig): AtomInstanceType<A>;
<A extends AnyAtomTemplate<{
Params: [];
}>>(template: A): AtomInstanceType<A>;
<A extends AnyAtomTemplate>(template: ParamlessTemplate<A>): AtomInstanceType<A>;
<I extends AnyAtomInstance>(instance: I, params?: [], config?: InjectAtomInstanceConfig): I;
};