zoukankan      html  css  js  c++  java
  • [RxJS] Split an RxJS observable with window

    Mapping the values of an observable to many inner observables is not the only way to create a higher order observable. RxJS also has operators that take a first order observable and return a higher order Observable. In this lesson we will learn about window, an operator to split an observable.

    'window' main task is to split observable to multi inner observables. That allows me do something useful to individual inner observable, such as 'scan' & 'count'.

    const clickObservable = Rx.Observable.fromEvent(document, 'click');
    const clockObservable = Rx.Observable.interval(1000);
    
    const resultObservable = clockObservable
      .window(clickObservable)
      .map(obs => obs.count())
      .switch();
    
    /*
    --0---1---2---3---4---5---6---7---8|
    --------c-----------c---c-----------
    
        window
        
    +-------+-----------+---+----------+
                                   
    --0---1-|-2---3---4-|-5-|-6---7---8|
    
          .map(o => o.count())
          
    --------+-----------+---+---------+     
                                   
    -------2|----------3|--1|--------3|
    
          switch
          
    --------2-----------3---1---------3      
    */
    
    resultObservable
      .subscribe(x => console.log(x));
  • 相关阅读:
    路由追踪BestTrace命令详解
    python MD5 信息摘要
    BFD 协议介绍
    IPSec 详细分析 二
    什么是分光器
    聊聊编码与解码(弄懂bytes,utf8,ascii,unicode)
    OS实践1: Windows 11 配置 WSL
    Mac上录屏录音
    同步相关 及音量
    iOS相关文档
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6208460.html
Copyright © 2011-2022 走看看