gpt4 book ai didi

angular - 在一个效果中分派(dispatch)多个 Action

转载 作者:太空狗 更新时间:2023-10-29 16:50:54 25 4
gpt4 key购买 nike

我想在一个效果中发送两个 Action 。目前我必须声明两种效果来实现这一点:

// first effect
@Effect()
action1$ = this.actions$
.ofType(CoreActionTypes.MY_ACTION)
.map(res => {
return { type: "ACTION_ONE"}
})
.catch(() => Observable.of({
type: CoreActionTypes.MY_ACTION_FAILED
}));

// second effect
@Effect()
action2$ = this.actions$
.ofType(CoreActionTypes.MY_ACTION)
.map(res => {
return { type: "ACTION_TWO"}
})
.catch(() => Observable.of({
type: CoreActionTypes.MY_ACTION_FAILED
}));

是否可能有一个 Action ,通过一个效果成为两个 Action 的来源?

最佳答案

@Effect()
loadInitConfig$ = this.actions$
.ofType(layout.ActionTypes.LOAD_INIT_CONFIGURATION)
.map<Action, void>(toPayload)
.switchMap(() =>
this.settingsService
.loadInitConfiguration()
.mergeMap((data: any) => [
new layout.LoadInitConfigurationCompleteAction(data.settings),
new meetup.LoadInitGeolocationCompleteAction(data.geolocation)
])
.catch(error =>
Observable.of(
new layout.LoadInitConfigurationFailAction({
error
})
)
)
);

关于angular - 在一个效果中分派(dispatch)多个 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41701138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com