UNPKG

selectorator

Version:

Simplified generator of reselect selectors

115 lines (114 loc) 3.85 kB
import type { Path as PathArray, PathItem } from 'pathington'; import type { CreateSelectorFunction, CreateSelectorOptions } from 'reselect'; import type { weakMapMemoize } from 'reselect'; import type { AnyFn, ComputeValue, ManualSelectInput, Path, PathObject, PathStructured, SelectStructuredInputs, StructuredValues, } from './internalTypes.d.cts'; /** * Whether the path is a functon */ export declare function isManualSelector<Params extends unknown[]>( path: Path<Params>, ): path is ManualSelectInput<Params>; /** * Whether the path is an object. */ export declare function isObjectPath(path: any): path is PathObject; export declare function isPathItem(path: any): path is PathItem; /** * Create the identity selector function based on the path passed. If the path item is a function then it is used directly, * otherwise the function is created based on its type. */ export declare function createIdentitySelector<Params extends unknown[]>(path: Path<Params>): (...args: any[]) => any; /** * Get the value at the deep location expected from the path. If no match is found, return `undefined`. */ export declare function getDeep<State>(path: PathArray, state: State): any; /** * Get the creator function to use when generating the selector. */ export declare function getSelectorCreator({ argsMemoize, argsMemoizeOptions, devModeChecks, memoize, memoizeOptions, }: CreateSelectorOptions): CreateSelectorFunction<typeof weakMapMemoize, typeof weakMapMemoize, any>; /** * Get a standard selector based on the paths and getComputedValue provided. */ export declare function getStandardSelector< const Params extends unknown[], const Paths extends Array<Path<Params>>, GetComputedValue extends ComputeValue<Params, Paths, any>, >( paths: Paths, selectorCreator: CreateSelectorFunction, getComputedValue: GetComputedValue, ): ((state: any) => any) & { clearCache: () => void; resultsCount: () => number; resetResultsCount: () => void; } & { resultFunc: (...resultFuncArgs: any[]) => any; memoizedResultFunc: ((...resultFuncArgs: any[]) => any) & { clearCache: () => void; resultsCount: () => number; resetResultsCount: () => void; }; lastResult: () => any; dependencies: ((...args: any[]) => any)[]; recomputations: () => number; resetRecomputations: () => void; dependencyRecomputations: () => number; resetDependencyRecomputations: () => void; } & { argsMemoize: typeof weakMapMemoize; memoize: typeof weakMapMemoize; }; /** * Get the structured object based on the computed selector values. */ export declare function getStructuredObject(properties: string[]): AnyFn; /** * Get an object of property => selected value pairs based on paths. */ export declare function getStructuredSelector( paths: PathStructured<any[]>, selectorCreator: CreateSelectorFunction, getComputedValue: AnyFn, ): ((state: any) => any) & { clearCache: () => void; resultsCount: () => number; resetResultsCount: () => void; } & { resultFunc: (...resultFuncArgs: any[]) => any; memoizedResultFunc: ((...resultFuncArgs: any[]) => any) & { clearCache: () => void; resultsCount: () => number; resetResultsCount: () => void; }; lastResult: () => any; dependencies: ((...args: any[]) => any)[]; recomputations: () => number; resetRecomputations: () => void; dependencyRecomputations: () => number; resetDependencyRecomputations: () => void; } & { argsMemoize: typeof weakMapMemoize; memoize: typeof weakMapMemoize; }; /** * Get an object of property => selected value pairs based on paths. */ export declare function getStructuredIdentitySelector< const Params extends unknown[], const Paths extends PathStructured<Params>, >(paths: Paths): (...values: StructuredValues<Params, Paths>) => SelectStructuredInputs<Params, Paths>;