如何在rxjs中将操作数据传递到可管道化操作符流的下游?

如何在rxjs中将操作数据传递到可管道化操作符流的下游?,rxjs,rxjs-pipeable-operators,Rxjs,Rxjs Pipeable Operators,我想在第三级操作中访问操作负载。 我可以在可出租运营商中实现这一点,但如何在可管道运营商中实现这一点 这是我的密码 @Effect() onTrySignin = this.actions$.pipe( ofType(AuthActions.TRY_SIGNIN), map((action: AuthActions.TrySignin) => { return action.payload; }), switchMap(action =&g

我想在第三级操作中访问操作负载。 我可以在可出租运营商中实现这一点,但如何在可管道运营商中实现这一点

这是我的密码

 @Effect()
  onTrySignin = this.actions$.pipe(
    ofType(AuthActions.TRY_SIGNIN),
    map((action: AuthActions.TrySignin) => {
      return action.payload;
    }),
    switchMap(action => {
      return this.httpService
        .postRequest('UserAccounts/Login', action.credentials);
    }), catchError((error: HttpErrorResponse) => {
      return Observable.of(new AuthActions.FailedAuth(error));
    }),
    mergeMap((response: any) => {
      // how to access action payload here?
    })
  );
您可以使用
map()

// both foo and bar will be available on next()
from(AsyncFooData()).pipe(
  concatMap(foo => AsyncBarData().pipe(
    map(bar => ({foo, bar})
  )),
  tap(val => console.log(val), // chain more operators here...
).subscribe(({foo, bar}) => {
  // do stuff with foo and bar
})

FWIW,我从我贴出的一个有点类似的答案中得到了这个答案。

好的,它是一个
管道
内部的
管道

 @Effect()
  onTrySignin = this.actions$.pipe(
    ofType(AuthActions.TRY_SIGNIN),
    map((action: AuthActions.TrySignin) => {
      return action.payload;
    }),
    switchMap(actionPayload => {
      return this.httpService.postRequest('UserAccounts/Login', actionPayload.credentials).pipe(
        mergeMap((response: HttpResponse<IApiResponder<string>>) => {
          switch (response.status) {
            case 200:
              if (actionPayload.returnUrl) {
                this.router.navigate([actionPayload.returnUrl]);
              } else {
                this.router.navigate(['/dbapp']);
              }
              return Observable.concat(
                Observable.of(new AuthActions.GenerateAntiforgeryToken()),
                Observable.of(new AuthActions.Signin(this.authService.getUserData())),
              );
          }
        }),
        catchError(e => {
          return Observable.of(new AuthActions.FailedAuth(e));
        }),
      );
    }),
  );
@Effect()
onTrySignin=this.actions$.pipe(
类型(AuthActions.TRY_sign),
映射((操作:authoctions.TrySignin)=>{
返回动作。有效载荷;
}),
开关映射(actionPayload=>{
返回此.httpService.postRequest('UserAccounts/Login',actionPayload.credentials)。管道(
合并映射((响应:HttpResponse)=>{
开关(响应状态){
案例200:
if(actionPayload.returnUrl){
this.router.navigate([actionPayload.returnUrl]);
}否则{
this.router.navigate(['/dbapp']);
}
返回可观察的.concat(
OfObservable.of(新建AuthActions.GenerateAntiforgeryToken()),
Observable.of(new AuthActions.Signin(this.authService.getUserData()),
);
}
}),
捕捉错误(e=>{
返回可观察的(新AuthActions.FailedAuth(e));
}),
);
}),
);

我正在重新阅读您的问题,并打算建议您从
postRequest
使用
管道
,这样您就可以访问
操作
。看起来你已经这么做了。很惊讶你把我的答案标记为正确,因为它并没有解决你的问题。。。但无论如何,干杯!:-)@kctang,您的回答让我想到了链式管道,这是我问题的核心解决方案,
AsyncFooData
和piping
AsyncBarData
,,谢谢:)