Skip to content

Commit

Permalink
fix: use appRef in api
Browse files Browse the repository at this point in the history
  • Loading branch information
SaulMoro committed Mar 14, 2024
1 parent b48dedd commit 99eba7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions projects/ngrx-rtk-query/src/lib/create-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ export const createApi: CreateApi<typeof coreModuleName | typeof angularHooksMod
}
return injector;
};
// eslint-disable-next-line ngrx/use-consistent-global-store-name
let storeFallback: Store;

const getStore = () => {
const injector = getApiInjector();
const store = 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?`);
}
storeFallback = store as Store;
return store;
};
const storeDispatch = (action: Action) => {
Expand Down
6 changes: 3 additions & 3 deletions projects/ngrx-rtk-query/src/lib/provide-store-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
ApplicationRef,
ENVIRONMENT_INITIALIZER,
Injector,
inject,
makeEnvironmentProviders,
type EnvironmentProviders,
Expand All @@ -23,8 +23,8 @@ export function provideStoreApi(
provide: ENVIRONMENT_INITIALIZER,
multi: true,
useValue() {
const injector = inject(Injector);
Object.assign(api, { injector });
const appRef = inject(ApplicationRef);
Object.assign(api, { injector: appRef.injector });
},
},
provideState(api.reducerPath, api.reducer),
Expand Down

0 comments on commit 99eba7d

Please sign in to comment.