NgRx EffectsModule 導入組 (NgRx EffectsModule imports group)


問題描述

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 DroutsasPoul Kruijt)

參考文件

  1. NgRx EffectsModule imports group (CC BY‑SA 2.5/3.0/4.0)

#ngrx-effects #ngrx #Angular #ngrx-store






相關問題

rxjs減少不繼續 (rxjs reduce does not continue)

從 reducer/action 觸發 API 重新加載的正確方法是什麼? (What's the proper way to trigger the API reload from reducer/action?)

Angular NgRx 效果,如何傳遞參數? (Angular NgRx effects, how to pass a parameter?)

NgRx 效果無限循環 (NgRx Effects infinite loop)

發送 forkjoin api,每個 api 之間有延遲 (Send forkjoin api with a delay in between each api)

如何從所有待處理的請求中取消特定請求 (How to cancel specific request from all pending request)

使用 NgRx 存儲優化 Angular 內存以避免內存洩漏 (Angular memory optimization with NgRx store to avoid memory leaks)

NgRx EffectsModule 導入組 (NgRx EffectsModule imports group)

切換地圖後在NGRX特效點擊功能中獲取動作道具 (Get action props in the NGRX effects tap function after switch Map)

如何防止在 NgRx 中第二次加載數據? (How prevent loading data second time in NgRx?)

需要幫助了解這種 Ngrx 效果 (Need help understanding this Ngrx effect)

測試效果 NgRx Angular 11 (Testing effects NgRx Angular 11)







留言討論