問題描述
從 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.
- This keeps your application clean
- The effect can easily be tested
</ul>
See Start using ngrx/effects for this for another example.
(by Fabio Picheli、timdeschryver)
參考文件