From bcec5f3431e5c234bf1cbdad9df625d581a11741 Mon Sep 17 00:00:00 2001 From: Saul Date: Tue, 26 Mar 2024 12:16:28 +0100 Subject: [PATCH] fix: test concurrent in noop store --- .../noop-store/src/provide-noop-store-api.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 a628371..91663ae 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 @@ -32,17 +32,11 @@ const createNoopStoreApi = ( api: Api, string, string, any>, { injector = inject(Injector) }: { injector?: Injector } = {}, ) => { - const store = injector.get(ApiStore); - const reducerPath = api.reducerPath; - const reducer = api.reducer as Reducer; - - // 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; + const dispatch = (action: UnknownAction) => { store.dispatch(action, { reducerPath, reducer }); return action; @@ -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 }; }; };