import { AutoDisposeOptions, Equality } from './types'; /** * A lazy-instantiation Map with factory function. * Items are created on-demand via `get()`. */ export interface Pool { (key: TKey): TValue; /** Call callback if key exists (does NOT create item). Chainable. */ tap(key: TKey, callback: (item: TValue) => void): this; /** Check if key exists (does NOT create item). */ has(key: TKey): boolean; /** Get item by key, creating it via factory if it doesn't exist. */ get(key: TKey): TValue; /** Explicitly set an item. Chainable. */ set(key: TKey, value: TValue): this; /** Number of items in the pool. */ size(): number; /** Remove all items. Calls dispose if autoDispose enabled. Chainable. */ clear(): this; /** Remove item by key. Calls dispose if autoDispose enabled. Chainable. */ delete(key: TKey): this; /** Iterate over keys. */ keys(): IterableIterator; /** Iterate over values. */ values(): IterableIterator; /** Iterate over [key, value] pairs. */ entries(): IterableIterator<[TKey, TValue]>; /** Subscribe to changes in the pool. */ on(listener: (event: PoolChangeEvent) => void): VoidFunction; } export interface PoolChangeEvent { key: TKey; value: TValue; type: TType; } export interface PoolOptions { initial?: readonly [TKey, TValue][]; /** * Custom equality function for keys (O(n) lookup). * For better performance, use `keyOf` instead. */ equality?: Equality; /** * Hash function to normalize keys (O(1) lookup). * Converts complex keys to a hashable string/number. * * @example * ```ts * // Object keys hashed by id * pool(createUser, { keyOf: (user) => user.id }) * * // Array keys hashed by JSON * pool(createItem, { keyOf: JSON.stringify }) * ``` */ keyOf?: (key: TKey) => string | number; /** * Automatically call dispose method of the item when it is removed from the pool. */ autoDispose?: AutoDisposeOptions | boolean; /** * Called when an item is added to the pool. */ onAdded?: (event: PoolChangeEvent) => void; /** * Called when an item is removed from the pool. */ onRemoved?: (event: PoolChangeEvent) => void; /** * Called when an item is added or removed from the pool. */ onChanged?: (event: PoolChangeEvent) => void; } /** * Lazy-instantiation Map wrapper. * * Creates items on first access via `get()`. Useful for managing * pools where items should be created on-demand. * * @example * ```ts * // Create a pool of emitters, one per property key * const emitters = pool((key: string) => emitter()); * * // First access creates the emitter * const countEmitter = emitters.get("count"); // creates new emitter * const countEmitter2 = emitters.get("count"); // returns same emitter * ``` * * @param createItem - Factory function to create new items * @param optionsOrInitial - Optional options or initial entries * @returns A Map-like object with lazy instantiation on `get()` */ export declare function pool(createItem: (key: TKey) => TValue, optionsOrInitial?: PoolOptions | readonly [TKey, TValue][]): Pool; //# sourceMappingURL=pool.d.ts.map