-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested reducers aren't working anymore with V4 #306
Comments
You need to use a reducer token if you're calling a function like app.module.ts import { BrowserModule } from '@angular/platform-browser'
import { NgModule } from '@angular/core'
import { StoreModule } from '@ngrx/store'
import { AppRoutingModule } from './app-routing.module'
import { AppComponent } from './app.component'
import { reducers, reducerToken, reducerProvider } from './reducers';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
StoreModule.forRoot(reducerToken),
],
providers: [reducerProvider],
bootstrap: [ AppComponent ]
})
export class AppModule { } reducers.ts import { ActionReducerMap, combineReducers } from '@ngrx/store'
import * as fromApp from './appReducers'
import * as fromNested from './nestedReducers'
import { InjectionToken } from '@angular/core';
export interface IState {
app: {
a: fromApp.IState,
b: fromNested.IState,
}
}
export const reducers = combineReducers({
a: fromApp.reducer,
b: fromNested.reducer,
});
export const reducerToken = new InjectionToken<ActionReducerMap<IState>>('Reducers');
export function getReducers() {
return {
app: reducers,
};
}
export const reducerProvider = [
{ provide: reducerToken, useFactory: getReducers }
]; |
Thanks a lot! Ok, I supposed that but what if Let's assume
How do I realize it now? Thanks a lot in advance. I really appreciate your help! |
You don't have to do anything different in nesting your reducers. The only change is how they get registered with the NgModule so it's AoT compatible |
There is a solution for nested reducers on V4 on this thread: ngrx/store#214 by @KwintenP |
@brandonroberts anyway you could show code how it would look like with another level of reducer nesting like brians example? |
@brandonroberts if I use your exact same pattern with the exception that I am doing
instead of
Does the |
I'm submitting a...
What is the current behavior?
I have to migrate a huge codebase using ngrx@v2 to ngrx@v4 (Cause we need the better support for lazy-loaded modules). In v2 we were able to use
combineReducers
even with AOT but after migrating to v4 there will be either a compile error according toresolving symbol values statically
or if I remove thecombineReducers
calls the reducers with nested reducers are missing on the state.The compile error:
If I use
npm start
(ng serve
) the first round of compiling fails with the error above, if I change a file and trigger the watcher all the subsequent compilations will be successful and the reducers work as expected.Expected behavior:
I want to use the current (nested) reducers (up to 5 levels deep in some cases). Of course I could flatten all the reducers but this would be a lot of refactoring I hope to avoid.
Minimal reproduction of the problem with instructions:
I created a small app which reproduces the behavior: https://github.com/Braincompiler/ngrx-nested-reducers (If you remove the combineReducers calls the state is empty).
The text was updated successfully, but these errors were encountered: