Skip to content

Commit

Permalink
fix: store instance in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SaulMoro committed Mar 14, 2024
1 parent 02c9c7a commit 65d65b5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions projects/ngrx-rtk-query/src/lib/create-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,30 @@ export const createApi: CreateApi<typeof coreModuleName | typeof angularHooksMod

const getApiInjector = () =>
(api as unknown as Api<any, Record<string, any>, string, string, AngularHooksModule | CoreModule>).injector;
let store: Store;
const getStore = () => {
if (store) return store;

const injector = getApiInjector();
if (!injector) {
throw new Error(
`Provide the API (${reducerPath}) is necessary to use the queries. Did you forget to provide the queries api?`,
);
}
const store = injector.get(Store, undefined, { optional: true });
const storeInstance = injector.get(Store, undefined, { optional: true });
if (!store) {
throw new Error(`Provide the Store is necessary to use the queries. Did you forget to provide the store?`);
}

store = storeInstance as Store;
return store;
};
const storeDispatch = (action: Action) => {
getStore().dispatch(action);
return action;
};
const storeState = () => {
const storeState = getStore().selectSignal((state) => state)();
const storeState: Record<string, any> = getStore().selectSignal((state) => state)();
return storeState?.[reducerPath]
? storeState
: // Query inside forFeature (Code splitting)
Expand Down

0 comments on commit 65d65b5

Please sign in to comment.