問題描述
NgRx EffectsModule 導入組 (NgRx EffectsModule imports group)
我試圖了解是否可以將所有 ngrx 效果組合/分組到一個對像中。我真正想問的是是否存在與效果等效的 ActionReducerMap (將化簡器分組)。在 app.module.ts
中,在我的 imports
數組中,我有以下內容:
...
StoreModule.forRoot(fromApp.appReducer),
EffectsModule.forRoot([DemoEffects, ModuleOneEffects, ModuleTwoEffects]),
...
有沒有辦法讓它更漂亮和分組 DemoEffects、ModuleOneEffects、ModuleTwoEffects
?
參考解法
方法 1:
I'm not sure if this answers your question, but you could do the following with the spread operator. Have a separate file with your effects:
export const miscEffects = [
DemoEffects
];
export const moduleEffects = [
ModuleOneEffects,
ModuleTwoEffects
];
Which you can then import in your NgModule
:
StoreModule.forRoot(fromApp.appReducer),
EffectsModule.forRoot([
...miscEffects ,
...moduleEffects,
...reallyCoolGroupedEffects
])
(by Stavros Droutsas、Poul Kruijt)