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


問題描述

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

我的問題是:處理這種情況的正確方法是什麼?目前我正在做的服務,比如:</p>

export const initialState: IMatchStore = {
  loading: false,
  needReload: true,
  matches: [],
};

但我覺得它可以改進和包裝一些效果


更新:

我已經設法創建了一個觀看 ActionTypes.Update 的效果,但它仍然不適合我:p

export const getAll = createSelector(
matchSelector,
({ matches }: IMatchStore) => unflatMatches(matches),
);

export const isLoading = createSelector(
matchSelector,
({ loading }: IMatchStore) => loading,
);

export const reload = createSelector(
matchSelector,
({ needReload, loading }: IMatchStore) => !loading && needReload,
);
</code></pre>


參考解法

方法 1:

The updated answer you posted is in my eyes the way to go.


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






相關問題

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)







留言討論