Splitting a stream into multiple streams causes new subscriptions. You can think of new subscriptions as "invoking a function". So if your original stream makes a request for data, splitting the original stream will make 2 requests for data. The way to get around this is by using share so that each time the stream is split, all the split stream stay synced together.

For the RxJS Code below, it issues network reuqest twice:

    const createLoader = url => from(this.$http.get(url)).pipe(pluck('data'));

    const luke$ = this.click$.pipe(
mapTo('https://starwars.egghead.training/people/1'),
switchMap(createLoader),
catchError(() => createLoader('https://starwars.egghead.training/people/2'))
); const name$ = luke$.pipe(pluck('name')); const image$ = luke$.pipe(
pluck('image'),
map(src => `https://starwars.egghead.training/${src}`)
);

Because both 'name$' and 'image$' will trigger 'luke$', then 'createLoader'.

In order to solve the problem we can use 'share()' or 'shareReplay(1)':

    const luke$ = this.click$.pipe(
mapTo('https://starwars.egghead.trainin/people/1'),
switchMap(createLoader),
catchError(() => createLoader('https://starwars.egghead.training/people/2')),
share()
);

最新文章

  1. jQuery选择器和选取方法 http://www.cnblogs.com/MaxIE/p/4078869.html
  2. 糖果 bzoj 2330
  3. 推荐几个精致的web UI框架
  4. 最新仿梦芭莎免费ecshop模板
  5. 第2章 数字之魅——寻找最大的K个数
  6. 在 Ubuntu 16.04 中安装谷歌 Chrome 浏览器
  7. Drupal commerce 性能优化
  8. phpDesigner 7.2.5 注册码 更改 语法高亮 主题
  9. Cloudra公司CCP:DS——认证数据专家
  10. [ofbiz]screen中应用form和ftl,控制页面元素属性
  11. ThinkPhp学习02
  12. PHP 反射类学习记录
  13. 深入剖析最新IE0day漏洞
  14. Json,Gson,Ajax基础知识
  15. Nginx实现集群服务器的负载均衡
  16. SpringBoot系列——花里胡哨的banner.txt
  17. 分布式任务调度系统xxl-job源码探究(二、服务中心)
  18. ps怎么撤销的三种方法和ps撤销快捷键以及连续撤销多步快捷键
  19. highcharts图表组件通过设置tooltip属性自定义数据提示信息
  20. HDU1070:Milk

热门文章

  1. 网站开发综合技术 第一部分HTML 1.3.2表单
  2. asp.net ajax get post 中文乱码解决办法
  3. 微信小程序授权 获取用户的openid和session_key【后端使用java语言编写】,我写的是get方式,目的是测试能否获取到微信服务器中的数据,后期我会写上post请求方式。
  4. 2017-12-04HTML table布局
  5. python的机器学习之路
  6. 关于vue构建项目的一些指令
  7. 安装好Pycharm后如何配置Python解释器简易教程
  8. Java多线程学习笔记(四)——Thread类中方法介绍
  9. oracle中的冷热备份
  10. axios在vue项目中的一种封装方法