Skip to content

Commit

Permalink
feat: export useSelector in api
Browse files Browse the repository at this point in the history
  • Loading branch information
SaulMoro committed Mar 22, 2024
1 parent db882ae commit 835109e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/ngrx-rtk-query/core/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ 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' {
export interface ApiModules<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -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.
*/
Expand All @@ -86,7 +92,7 @@ export interface AngularHooksModuleOptions {
/**
* The version of the `useSelector` hook to be used
*/
useSelector: <K>(mapFn: (state: any) => K, options?: { equal?: ValueEqualityFn<K> }) => Signal<K>;
useSelector: UseSelector;
};
/**
* A selector creator (usually from `reselect`, or matching the same signature)
Expand Down Expand Up @@ -128,6 +134,7 @@ export const angularHooksModule = ({
});
safeAssign(anyApi, { usePrefetch });
safeAssign(anyApi, { dispatch: hooks.dispatch });
safeAssign(anyApi, { useSelector: hooks.useSelector });
safeAssign(anyApi, { getInjector });

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, any>>({});

Expand Down Expand Up @@ -66,6 +66,7 @@ export function provideNoopStoreApi(
setupListeners === false ? undefined : setupListenersFn(api.dispatch, setupListeners);

return makeEnvironmentProviders([
ApiStore,
{
provide: ENVIRONMENT_INITIALIZER,
multi: true,
Expand Down

0 comments on commit 835109e

Please sign in to comment.