我的应用程序的其中一个 ngrx 效果有问题。我基本上是在尝试使用concatMap()
并使用路由器商店的go()
.
这是效果:
@Effect()
loadPersonalInfoAndSignin$: Observable<Action> = this.actions$
.ofType(session.ActionTypes.LOAD_PERSONAL_INFO)
.map((action: LoadPersonalInfoAction) => action.payload)
.do(sessionToken => {
localStorage.setItem('authenticated', 'true');
localStorage.setItem('sessionToken', sessionToken);
})
.switchMap(() => this.userAccountService
.retrieveCurrentUserAccount()
.concatMap(currentUserAccount => [
new LoadUserAccountAction(currentUserAccount),
new SigninAction(),
new LoadMessagesAction({})
])
)
.mapTo(go(['/dashboard']));
如果我删除.mapTo(go(['/dashboard']))
,那么concatMap
数组中的所有三个动作都会成功地分派到它们相应的效果。
因此,我想知道为什么 mymapTo(go(...
导致数组中的最后两个动作(即SigninAction
& LoadMessagesAction
)没有被分派到它们相应的效果..
有人可以帮忙吗?
编辑:更改mapTo
为do
如下:
.do(go(['/dashboard']));
导致以下错误:
ERROR in /Users/julien/Documents/projects/bignibou/bignibou-client/src/app/core/store/session/session.effects.ts (55,9): Argument of type 'Action' is not assignable to parameter of type 'PartialObserver<SigninAction>'.
Type 'Action' is not assignable to type 'CompletionObserver<SigninAction>'.
Property 'complete' is missing in type 'Action'.