UNPKG

ngrx-rtk-query

Version:
81 lines (80 loc) 3.69 kB
import { type Injector, type Signal, type ValueEqualityFn } from '@angular/core'; import { type Action, type Selector, type ThunkAction } from '@reduxjs/toolkit'; import { type BaseQueryFn, type EndpointDefinitions, type InfiniteQueryDefinition, type Module, type MutationDefinition, type PrefetchOptions, type QueryArgFrom, type QueryDefinition, type QueryKeys } from '@reduxjs/toolkit/query'; import { type HooksWithUniqueNames, type InfiniteQueryHooks, type MutationHooks, type QueryHooks } from './types'; export declare const angularHooksModuleName: unique symbol; export type AngularHooksModule = typeof angularHooksModuleName; export type Dispatch = <ReturnType>(action: Action | ThunkAction<ReturnType, any, any, Action>) => ReturnType extends Action ? Action : ReturnType; export type UseSelector = <K>(mapFn: (state: any) => K, options?: { equal?: ValueEqualityFn<K>; }) => Signal<K>; declare module '@reduxjs/toolkit/query' { interface ApiModules<BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string> { [angularHooksModuleName]: { /** * Endpoints based on the input endpoints provided to `createApi`, containing `select`, `hooks` and `action matchers`. */ endpoints: { [K in keyof Definitions]: Definitions[K] extends QueryDefinition<any, any, any, any, any> ? QueryHooks<Definitions[K]> : Definitions[K] extends MutationDefinition<any, any, any, any, any> ? MutationHooks<Definitions[K]> : Definitions[K] extends InfiniteQueryDefinition<any, any, any, any, any> ? InfiniteQueryHooks<Definitions[K]> : never; }; /** * A hook that accepts a string endpoint name, and provides a callback that when called, * pre-fetches the data for that endpoint. */ usePrefetch<EndpointName extends QueryKeys<Definitions>>(endpointName: EndpointName, options?: PrefetchOptions): (arg: QueryArgFrom<Definitions[EndpointName]>, options?: PrefetchOptions) => void; /** * Provides access to the api dispatch function. */ dispatch: Dispatch; /** * Provides access to the api selectSignal function. */ selectSignal: UseSelector; /** * Provides access to the api injector. */ getInjector: () => Injector; } & HooksWithUniqueNames<Definitions>; } } export interface AngularHooksModuleOptions { /** * The hooks from Redux to be used */ hooks: { /** * The version of the `dispatch` to be used */ dispatch: Dispatch; /** * The version of the `getState` to be used */ getState: () => any; /** * The version of the `useSelector` hook to be used */ useSelector: UseSelector; }; /** * A selector creator (usually from `reselect`, or matching the same signature) */ createSelector: <T = any, V = any>(...input: any[]) => Selector<T, V>; /** * The injector to be used */ getInjector: () => Injector; } /** * Creates a module that generates angular hooks from endpoints, for use with `buildCreateApi`. * * @example * ```ts * const customCreateApi = buildCreateApi( * coreModule(), * angularHooksModule(() => myCreateAngularHooksModule()) * ); * ``` * * @returns A module for use with `buildCreateApi` */ export declare const angularHooksModule: ({ hooks, createSelector, getInjector, }: AngularHooksModuleOptions) => Module<AngularHooksModule>;