[英]NgRx calling actions from effects at the beginning
我正在嘗試在效果之前或開始時發送一個動作。
小例子:
saveSomething$ = createEffect(() =>
this.actions$.pipe(
ofType(SaveProjectAction),
tap(() => ImSavingNowAction()), // trigger action here
withLatestFrom(this.store.select(selectSomething)),
mergeMap(([action, project]) => {
let save$ = this.api.call(something); // Do an api call or something that takes long here
return save$.pipe(
map(
(project) => SavedSomethingAction({ something }),// Next Action to be called
catchError(() => EMPTY)
)
);
})
)
);
我認為最好在調度第一個動作后直接在reducer
中處理它,而無需從effect
調度ImSavingNowAction
動作。
一般來說,最佳實踐實際上是處理一個或多個動作,並將它們 map 處理為一個單獨的動作,而不在其中調度任何其他action
。
您可以查看no-dispatch-in-effects和no-multiple-actions-in-effects規則以獲取更多詳細信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.