From 835109e74c9beb061a7ce8cac1aae47e4ebe093a Mon Sep 17 00:00:00 2001 From: Saul Date: Fri, 22 Mar 2024 11:39:49 +0100 Subject: [PATCH] feat: export useSelector in api --- packages/ngrx-rtk-query/core/src/module.ts | 9 ++++++++- .../noop-store/src/provide-noop-store-api.ts | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/ngrx-rtk-query/core/src/module.ts b/packages/ngrx-rtk-query/core/src/module.ts index 8ebd2f0..f0fe31f 100644 --- a/packages/ngrx-rtk-query/core/src/module.ts +++ b/packages/ngrx-rtk-query/core/src/module.ts @@ -29,6 +29,8 @@ export type Dispatch = ( action: Action | ThunkAction, ) => ReturnType extends Action ? Action : ReturnType; +export type UseSelector = (mapFn: (state: any) => K, options?: { equal?: ValueEqualityFn }) => Signal; + declare module '@reduxjs/toolkit/query' { export interface ApiModules< // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -62,6 +64,10 @@ declare module '@reduxjs/toolkit/query' { * Provides access to the api dispatch function. */ dispatch: Dispatch; + /** + * Provides access to the api useSelector function. + */ + useSelector: UseSelector; /** * Provides access to the api injector. */ @@ -86,7 +92,7 @@ export interface AngularHooksModuleOptions { /** * The version of the `useSelector` hook to be used */ - useSelector: (mapFn: (state: any) => K, options?: { equal?: ValueEqualityFn }) => Signal; + useSelector: UseSelector; }; /** * A selector creator (usually from `reselect`, or matching the same signature) @@ -128,6 +134,7 @@ export const angularHooksModule = ({ }); safeAssign(anyApi, { usePrefetch }); safeAssign(anyApi, { dispatch: hooks.dispatch }); + safeAssign(anyApi, { useSelector: hooks.useSelector }); safeAssign(anyApi, { getInjector }); return { diff --git a/packages/ngrx-rtk-query/noop-store/src/provide-noop-store-api.ts b/packages/ngrx-rtk-query/noop-store/src/provide-noop-store-api.ts index 29d2280..dd725df 100644 --- a/packages/ngrx-rtk-query/noop-store/src/provide-noop-store-api.ts +++ b/packages/ngrx-rtk-query/noop-store/src/provide-noop-store-api.ts @@ -15,7 +15,7 @@ import { type Api, setupListeners as setupListenersFn } from '@reduxjs/toolkit/q import { type AngularHooksModuleOptions, type Dispatch, type StoreQueryConfig } from 'ngrx-rtk-query/core'; -@Injectable({ providedIn: 'root' }) +@Injectable() export class ApiStore { readonly state = signal>({}); @@ -66,6 +66,7 @@ export function provideNoopStoreApi( setupListeners === false ? undefined : setupListenersFn(api.dispatch, setupListeners); return makeEnvironmentProviders([ + ApiStore, { provide: ENVIRONMENT_INITIALIZER, multi: true,