UNPKG

3.92 kBTypeScriptView Raw
1import type { Selector, GetParamsFromSelectors, OutputSelector, SelectorArray, SelectorResultArray, DropFirst, MergeParameters, Expand, ObjValueTuple, Head, Tail } from './types';
2export type { Selector, GetParamsFromSelectors, GetStateFromSelectors, OutputSelector, EqualityFn, SelectorArray, SelectorResultArray, ParametricSelector, OutputParametricSelector, OutputSelectorFields } from './types';
3import { defaultMemoize, defaultEqualityCheck, DefaultMemoizeOptions } from './defaultMemoize';
4export { defaultMemoize, defaultEqualityCheck };
5export type { DefaultMemoizeOptions };
6export declare function createSelectorCreator<
7/** Selectors will eventually accept some function to be memoized */
8F extends (...args: unknown[]) => unknown,
9/** A memoizer such as defaultMemoize that accepts a function + some possible options */
10MemoizeFunction extends (func: F, ...options: any[]) => F,
11/** The additional options arguments to the memoizer */
12MemoizeOptions extends unknown[] = DropFirst<Parameters<MemoizeFunction>>>(memoize: MemoizeFunction, ...memoizeOptionsFromArgs: DropFirst<Parameters<MemoizeFunction>>): CreateSelectorFunction<F, MemoizeFunction, MemoizeOptions, Expand<Pick<ReturnType<MemoizeFunction>, keyof ReturnType<MemoizeFunction>>>>;
13export interface CreateSelectorOptions<MemoizeOptions extends unknown[]> {
14 memoizeOptions: MemoizeOptions[0] | MemoizeOptions;
15}
16/**
17 * An instance of createSelector, customized with a given memoize implementation
18 */
19export interface CreateSelectorFunction<F extends (...args: unknown[]) => unknown, MemoizeFunction extends (func: F, ...options: any[]) => F, MemoizeOptions extends unknown[] = DropFirst<Parameters<MemoizeFunction>>, Keys = Expand<Pick<ReturnType<MemoizeFunction>, keyof ReturnType<MemoizeFunction>>>> {
20 /** Input selectors as separate inline arguments */
21 <Selectors extends SelectorArray, Result>(...items: [
22 ...Selectors,
23 (...args: SelectorResultArray<Selectors>) => Result
24 ]): OutputSelector<Selectors, Result, (...args: SelectorResultArray<Selectors>) => Result, GetParamsFromSelectors<Selectors>, Keys> & Keys;
25 /** Input selectors as separate inline arguments with memoizeOptions passed */
26 <Selectors extends SelectorArray, Result>(...items: [
27 ...Selectors,
28 (...args: SelectorResultArray<Selectors>) => Result,
29 CreateSelectorOptions<MemoizeOptions>
30 ]): OutputSelector<Selectors, Result, ((...args: SelectorResultArray<Selectors>) => Result), GetParamsFromSelectors<Selectors>, Keys> & Keys;
31 /** Input selectors as a separate array */
32 <Selectors extends SelectorArray, Result>(selectors: [...Selectors], combiner: (...args: SelectorResultArray<Selectors>) => Result, options?: CreateSelectorOptions<MemoizeOptions>): OutputSelector<Selectors, Result, (...args: SelectorResultArray<Selectors>) => Result, GetParamsFromSelectors<Selectors>, Keys> & Keys;
33}
34export declare const createSelector: CreateSelectorFunction<(...args: unknown[]) => unknown, typeof defaultMemoize, [equalityCheckOrOptions?: import("./types").EqualityFn | DefaultMemoizeOptions | undefined], {
35 clearCache: () => void;
36}>;
37type SelectorsObject = {
38 [key: string]: (...args: any[]) => any;
39};
40export interface StructuredSelectorCreator {
41 <SelectorMap extends SelectorsObject, SelectorParams = MergeParameters<ObjValueTuple<SelectorMap>>>(selectorMap: SelectorMap, selectorCreator?: CreateSelectorFunction<any, any, any>): (state: Head<SelectorParams>, ...params: Tail<SelectorParams>) => {
42 [Key in keyof SelectorMap]: ReturnType<SelectorMap[Key]>;
43 };
44 <State, Result = State>(selectors: {
45 [K in keyof Result]: Selector<State, Result[K], never>;
46 }, selectorCreator?: CreateSelectorFunction<any, any, any>): Selector<State, Result, never>;
47}
48export declare const createStructuredSelector: StructuredSelectorCreator;