import { AtomSelectorOrConfig, Cleanup, DependentCallback, DependentEdge, EvaluationReason, Selectable } from '../types/index.js'; import { Ecosystem } from './Ecosystem.js'; export declare class SelectorCache { id: string; selectorRef: AtomSelectorOrConfig; args?: Args | undefined; static $$typeof: symbol; isDestroyed?: boolean; isMaterialized?: boolean; nextReasons: EvaluationReason[]; prevReasons?: EvaluationReason[]; result?: T; task?: () => void; _lastEdge?: WeakRef; _prevCache?: WeakRef; constructor(id: string, selectorRef: AtomSelectorOrConfig, args?: Args | undefined); } /** * Since AtomSelectors are meant to feel lightweight, they don't have to be * instances of a class - they'll often be standalone or even inline * functions. This class handles all the logic that AtomSelectors would handle * themselves if they were classes - creation, cache management, and * destruction. */ export declare class Selectors { private readonly ecosystem; /** * Map selectorKey + params id strings to the SelectorCache for the selector */ _items: Record>; /** * A workaround for React StrictMode */ _lastCache?: WeakRef>; /** * Map selectors (or selector config objects) to a base selectorKey that can * be used to predictably create selectorKey+params ids to look up the cache * in `this._items` */ _refBaseKeys: WeakMap, string>; constructor(ecosystem: Ecosystem); addDependent(cacheItem: SelectorCache, { callback, operation, }?: { callback?: DependentCallback; operation?: string; }): Cleanup; /** * Get an object mapping all ids in this selectorCache to their current * values. * * Pass a selector to only return caches of that selector. * * Pass a partial SelectorCache id string to only return caches whose id * contains the passed key (case-insensitive). * * IMPORTANT: Don't use this for SSR. SelectorCaches are not designed to be * shared across environments. Selectors should be simple derivations that * will be predictably recreated from rehydrated atom instances. * * In other words, `ecosystem.dehydrate()` is all you need for SSR. Don't * worry about selectors. This method is solely an inspection/debugging util. */ dehydrate(selectableOrName?: Selectable | string): Record>; destroyCache(selectable: Selectable): void; destroyCache(selectable: Selectable, args: Args, force?: boolean): void; /** * Get the cache for the given selector. Return undefined if it doesn't exist * yet - don't create it. */ find(selectable: Selectable): SelectorCache | undefined; find(selectable: Selectable, args: Args): SelectorCache | undefined; find(selectable: string): SelectorCache | undefined; /** * Get an object of all currently-cached AtomSelectors. * * Pass a selector reference or string to filter by caches whose id * weakly matches the passed selector name. */ findAll(selectableOrName?: Selectable | string): Record>; getCache(selectable: Selectable): SelectorCache; getCache(selectable: Selectable, args: Args): SelectorCache; getCacheId(selectorOrConfig: AtomSelectorOrConfig): string; getCacheId(selectorOrConfig: AtomSelectorOrConfig, args: Args): string; getCacheId(selectorOrConfig: AtomSelectorOrConfig, args: Args, weak: true): string | undefined; /** * Should only be used internally. Removes the selector from the cache and * the graph */ _destroySelector(id: string): void; /** * Get the string key we would ideally use as the id of the given * AtomSelector function or AtomSelectorConfig object - doesn't necessarily * mean we end up caching using this key. */ _getIdealCacheId(selectorOrConfig: AtomSelectorOrConfig): string | undefined; /** * Should only be used internally */ _scheduleEvaluation(id: string, reason: EvaluationReason, shouldSetTimeout?: boolean): void; /** * Should only be used internally */ _swapRefs(oldCache: SelectorCache, newRef: AtomSelectorOrConfig, args?: any[]): void; /** * Destroy all cached selectors. Should probably only be used internally. * Prefer `ecosystem.reset()`. */ _wipe(): void; /** * Get a base key that can be used to generate consistent ids for the given * selector */ private getBaseKey; /** * Run an AtomSelector and, depending on the selector's resultsComparator, * update its cached result. Updates the graph efficiently (using * `.bufferUpdates()`) */ private runSelector; }