Angular 6 w/NgRX 4を使用しています。複数のレデューサーを組み合わせたいのですが。
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import { AppComponent } from './app.component';
import counterEffects from './store/counter/counter.effects';
import reducers from './store/reducers';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
StoreModule.forRoot(reducers),
EffectsModule.forRoot([counterEffects]),
StoreDevtoolsModule.instrument({
maxAge: 10,
}),
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
reducers.ts
import { combineReducers } from '@ngrx/store';
import { reducer as counterReducer, key as counterKey } from './counter';
import { reducer as profileReducer, key as profileKey } from './profile';
const appReducer = combineReducers({
[counterKey]: counterReducer,
[profileKey]: profileReducer,
});
export default (state, action) => {
if (action.type === 'REDIRECT_TO_EXTERNAL') {
state = undefined;
}
return appReducer(state, action);
};
私の減速機は標準的な減速機であり、特別なものはありません。
React/Redux backgroundから来て、このように複数のレデューサーを設定しますが、Angularでストアから選択しようとすると、未定義になります。開発ツールを使用してストアを表示しようとすると、リデューサーがまったく表示されず、状態は{}
Angular 6/NgRX 4)で複数のレデューサーを設定するにはどうすればよいですか?
import { ActionReducerMap } from '@ngrx/store';
import { reducer as counterReducer, key as counterKey } from './counter';
import { reducer as profileReducer, key as profileKey } from './profile';
export interface IAppState {
[counterKey]: any;
[profileKey]: any;
}
export const reducers: ActionReducerMap<IAppState> = {
[counterKey]: counterReducer,
[profileKey]: profileReducer,
};