This lesson will highlight the true purpose of the zip operator, and how uncommon its use cases are. In its place, we will learn how to use the combineLatest operator.

const length$ = Rx.Observable.of(, );
const width$ = Rx.Observable.of(,);
const height$ = Rx.Observable.of(2.8, 2.5); const volume$ = Rx.Observable
.zip(length$, width$, height$,
(length, width, height) => length * width * height
); volume$.subscribe(function (volume) {
console.log(volume);
});

zip requiers each observable has synchronized emissions.  It means:

const length$ = Rx.Observable.of();
const width$ = Rx.Observable.of();
const height$ = Rx.Observable.of(2.8, 2.5);

2.5 won't be calculated only when lenth$ and width$ provide second value.

In this case we can use combineLatest instead of zip:

const length$ = Rx.Observable.of();
const width$ = Rx.Observable.of();
const height$ = Rx.Observable.of(2.8, 2.5); const volume$ = Rx.Observable
.combineLatest(length$, width$, height$,
(length, width, height) => length * width * height
); volume$.subscribe(function (volume) {
console.log(volume);
});

One useful tip for using zip:

zip can spread sync value over time, when combine with interval

const source$ = of('hello')
const interval$ = interval().take() source$.zip(interval$, (s, n) => s)
.subscribe() /*
source$: (hello)|
interval$ ----0----1----2----3----4 zip ----h----e----l----l----o
*/

The same effect can also be done with concatMap + delay

const source$ = of('hello')
source$.concatMap(x => of(x).delay())

[RxJS] Replace zip with combineLatest when combining sources of data的更多相关文章

  1. RxJS v6 学习指南

    为什么要使用 RxJS RxJS 是一套处理异步编程的 API,那么我将从异步讲起. 前端编程中的异步有:事件(event).AJAX.动画(animation).定时器(timer). 异步常见的问 ...

  2. Angular快速学习笔记(4) -- Observable与RxJS

    介绍RxJS前,先介绍Observable 可观察对象(Observable) 可观察对象支持在应用中的发布者和订阅者之间传递消息. 可观察对象可以发送多个任意类型的值 -- 字面量.消息.事件. 基 ...

  3. python3 解决zip解压中文乱码问题,亲测可用, ZipFile

    中文乱码是个很头疼的问题,找了好久都没用找到解决办法 后来也忘了在哪儿找到的解决办法, 很久以前了,但不可行, 解决了思路 在源码里面想要修改内容 if flags & 0x800: # UT ...

  4. rxjs入门6之合并数据流

    一 concat,merge,zip,combineLatest等合并类操作符 以上操作符在版本6中已经只存在静态方法,不能在pipe中使用. import {concat,merge,zip,com ...

  5. 【转】Rxjs知识整理

    原文:https://www.jianshu.com/p/16be96d69143 ---------------------------------------------------------- ...

  6. RxJS 6有哪些新变化?

    我们的前端工程由Angular4升级到Angular6,rxjs也要升级到rxjs6.  rxjs6的语法做了很大的改动,幸亏引入了rxjs-compact包,否则升级工作会无法按时完成. 按照官方的 ...

  7. java zip 工具类

    原文:http://www.open-open.com/code/view/1430906539866 package com.topsoft.websites.utils; import java. ...

  8. Java 解压 zip 文件

    代码如下 package test_java; import java.io.File; import java.io.FileOutputStream; import java.io.IOExcep ...

  9. Like ruby of SBM Crusher zip to dict

    how to use the zip to bulid a dict in python? data = """A dynamic, interpreted, open ...

随机推荐

  1. 源码安装 ipython

    https://blog.csdn.net/huobanjishijian/article/details/51470898

  2. 清除celery 任务队列

    celery 有密码的时候 清除任务 redis-cli -h host -p port -a password -n 11 ltrim transcode 0 196 没有密码的时候 redis-c ...

  3. Axios再记录

    一个基于Promise 用于浏览器和 nodejs 的 HTTP 客户端(可实现ajax的请求) 有关学习网址:https://www.tuicool.com/articles/eMb2yuY    ...

  4. 洛谷P2234 [HNOI2002]营业额统计(01Tire树)

    题目描述 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每天的营业额.分析营业情况是 ...

  5. Android 使用AIDL实现进程间的通信

    在Android中,如果我们需要在不同进程间实现通信,就需要用到AIDL技术去完成. AIDL(android Interface Definition Language)是一种接口定义语言,编译器通 ...

  6. 如果输入的不是英文字母或者数字或者汉字,则返回false

    public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_C ...

  7. react radio onchange事件点击无效

    记: 项目需求:   页面中radio默认选中        第一次进去页面   点击radio的时候不管怎样点击    都是选中 连onChange事件都没触发 进入页面  点击刷新   点击rad ...

  8. [USACO08JAN]电话线Telephone Lines(分层图)/洛谷P1948

    这道题其实是分层图,但和裸的分层图不太一样.因为它只要求路径总权值为路径上最大一条路径的权值,但仔细考虑,这同时也满足一个贪心的性质,那就是当你每次用路径总权值小的方案来更新,那么可以保证新的路径权值 ...

  9. Spring学习总结(5)——IOC注入方式总结

    一.构造注入 在类被实例化的时候,它的构造方法被调用并且只能调用一次.所以它被用于类的初始化操作.<constructor-arg>是<bean>标签的子标签.通过其<v ...

  10. StartCoroutine的使用

    StartCoroutine在unity3d的帮助中叫做协程,意思就是启动一个辅助的线程. 在C#中直接有Thread这个线程,可是在unity中有些元素是不能操作的.这个时候能够使用协程来完毕. 使 ...