Har*_*lue 6 redux ngrx angular
我正在使用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 {}
Run Code Online (Sandbox Code Playgroud)
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);
};
Run Code Online (Sandbox Code Playgroud)
我的减速机是标准的减速机,没什么特别的.
来自React/Redux背景,我会像这样设置多个reducers,但是在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,
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5258 次 |
| 最近记录: |