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. xml格式报文的拼装,和解析成实体类

    我们的微信支付,使用的是第三方的支付,某银行的微信支持渠道.所有的接口请求.应答都是xml格式报文,这样就需要用到xml格式报文的拼装和解析,这儿简单讲一下. 拼接xml格式报文. 从页面表单提交和配 ...

  2. HDU 3072--Intelligence System【SCC缩点新构图 && 求连通全部SCC的最小费用】

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  3. AsyncTask源代码翻译

    前言: /** <p>AsyncTask enables proper and easy use of the UI thread. This class allows to perfor ...

  4. Java IO:SocketChannel和Selector在ZooKeeper中应用

    转载请注明出处:jiq•钦's technical Blog 假设不了解SocketChannel和Selector.请先阅读我的还有一篇博文:点击打开链接 ZooKeeper的启动从QuorumPe ...

  5. Android开发经验一判断当前屏幕是全屏还是非全屏

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView ...

  6. android图像处理(3)底片效果

    这篇将讲到图片特效处理的底片效果.跟前面一样是对像素点进行处理,算法是通用的. 算法原理:将当前像素点的RGB值分别与255之差后的值作为当前点的RGB值. 例: ABC 求B点的底片效果: B.r ...

  7. angularjs 合并单元格

    Html: <table class="table table-striped"> <thead> <tr> <th>国家</ ...

  8. jQuery选择器,Ajax请求

    jQuery选择器: $("#myELement") 选择id值等于myElement的元素,id值不能重复在文档中只能有一个id值是myElement所以得到的是唯一的元素 $( ...

  9. BZOJ3676: [Apio2014]回文串(SAM+Manacher/PAM)

    Description 考虑一个只包含小写拉丁字母的字符串s.我们定义s的一个子串t的“出 现值”为t在s中的出现次数乘以t的长度.请你求出s的所有回文子串中的最 大出现值. Input 输入只有一行 ...

  10. 1.字符设备驱动------Linux中断处理体系结构

    一.中断处理体系结构的初始化 Linux内核将所有的中断统一编号,使用一个irq_desc结构数组来描述这些中断;每个数组项对应一个中断,也可能是一组中断,它们共用相同的中断号,里面记录了中断的名称. ...