Skip to content

Commit

Permalink
fix: test concurrent in noop store
Browse files Browse the repository at this point in the history
  • Loading branch information
SaulMoro committed Mar 26, 2024
1 parent dbd139f commit bcec5f3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/ngrx-rtk-query/noop-store/src/provide-noop-store-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,11 @@ const createNoopStoreApi = (
api: Api<any, Record<string, any>, string, string, any>,
{ injector = inject(Injector) }: { injector?: Injector } = {},
) => {
const store = injector.get(ApiStore);
const reducerPath = api.reducerPath;
const reducer = api.reducer as Reducer<any>;

// Initialize the store with the initial state
const currentApiState = api.selectSignal?.((state: any) => state?.[reducerPath])?.();
if (!currentApiState) {
store.state.update((state) => ({ ...state, [reducerPath]: {} }));
}

return (): AngularHooksModuleOptions => {
const store = injector.get(ApiStore);
const reducerPath = api.reducerPath;
const reducer = api.reducer as Reducer<any>;

const dispatch = (action: UnknownAction) => {
store.dispatch(action, { reducerPath, reducer });
return action;
Expand All @@ -58,6 +52,12 @@ const createNoopStoreApi = (
input.reduce((acc, selector) => selector(acc), state);
const getInjector = () => injector;

// Initialize the store with the initial state
const currentApiState = api.selectSignal?.((state: any) => state?.[reducerPath])?.();
if (!currentApiState) {
store.state.update((state) => ({ ...state, [reducerPath]: {} }));
}

return { hooks, createSelector, getInjector };
};
};
Expand Down

0 comments on commit bcec5f3

Please sign in to comment.