通过多个参数传递给rxjs运算符 [英] Passing through multiple parameters to rxjs operator

查看:84
本文介绍了通过多个参数传递给rxjs运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有更优雅的方法来进行以下操作?

Is there a more elegant way of doing the following?

private getHeaders(): Observable<any> {
  let version;
  let token;
  return this.appInfo.getVersion()
    .pipe(
      tap(appVersion => version = appVersion),
      mergeMap(() => this.storage.get('access_token')),
      tap(accessToken => token = accessToken),
      mergeMap(accessToken => of(this.createHeaders(version, token)))
    );
}

我如何能更流利地记住this.appInfo.getVersion()this.storage.get('access_token')的两个返回值,而不用rxjs的功能将它们写入临时变量?

How can I more fluently remember the two return values of this.appInfo.getVersion() and this.storage.get('access_token') without writing them to temporary variables with the power of rxjs?

也许将一些观测值合并为一个? rxjs运算符和东西太多了...

Perhaps merging some observables into one? There are so many rxjs operators and stuff...

推荐答案

使用 forkJoin ,它是为这种情况而设计的.

Use forkJoin, it's designed for this type of situation.

这篇关于通过多个参数传递给rxjs运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆