#Several slices of the global state

8 messages · Page 1 of 1 (latest)

frozen niche
#

Several slices of the global state in NGRX - is this how they are registered for standalone app?
In the official docs - I didn’t find an example, I didn’t search well, maybe

import {
  authFeatureKey,
  authReducer,
} from './components/auth/store/reducers/auth.reducer';
import { provideEffects } from '@ngrx/effects';
import * as authEffects from './components/auth/store/effects/auth.effect';
import * as currentUserEffects from './components/auth/store/effects/current-user.effect';
import * as feedEffects from './components/feeds/store/effects/feed.effect';
import { CurrentUserAction } from './components/auth/store/actions';
import { IGlobalState } from './interfaces';
import {
  feedsFeatureKey,
  feedsReducer,
} from './components/feeds/store/reducers';

function initializeApplication(store: Store<IGlobalState>): () => void {
  return (): void => store.dispatch(CurrentUserAction.get());
}

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(routes),
    provideStore(),
    provideState({ name: authFeatureKey, reducer: authReducer }),
    provideState({ name: feedsFeatureKey, reducer: feedsReducer }),
    provideEffects(authEffects, currentUserEffects, feedEffects),
    provideStoreDevtools({ maxAge: 25, logOnly: !isDevMode() }),
    provideHttpClient(withInterceptors([loginInterceptor])),
    // we can provide the desired Storage (localStorage, sessionStorage, etc.) to our Angular application
    {
      provide: STORAGE,
      useValue: localStorage,
    },
    {
      provide: APP_INITIALIZER,
      useFactory: initializeApplication,
      multi: true,
      deps: [Store],
    },
  ],
};
#

devtools says - it is true; apparently the issue has been resolved?

frozen niche
#

module-based app

ebon shadow
#

Oops, no what you have is correct (I missed the overload that takes in a FeatureSlice, which is the object you're passing in https://ngrx.io/api/store/FeatureSlice). So yes, this looks correct for a standalone app.