[RxJS] Split an RxJS Observable into groups with groupBy

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[RxJS] Split an RxJS Observable into groups with groupBy相关的知识,希望对你有一定的参考价值。

groupBy() is another RxJS operator to create higher order observables. In this lesson we will learn how groupBy works for routing source values into different groups according to a calculated key.

 

const numbersObservable = Rx.Observable.interval(500).take(5);

numbersObservable
  .groupBy(x => x % 2)
  .map(innerObs => innerObs.count())
  .mergeAll()
  .subscribe(x => console.log(x));

/*
--0--1--2--3--4|

 groupBy(x => x % 2)
 
--+--+---------|
  \    \  1-----3---|
  0-----2-----4|
  
 map(innerObs => innerObs.count())
 
--+--+---------|
  \    \  ---------2|
  ------------3|
  
 mergeAll
 
--------------(3,2)|

*/

 

以上是关于[RxJS] Split an RxJS Observable into groups with groupBy的主要内容,如果未能解决你的问题,请参考以下文章

[RxJS] Subject: an Observable and Observer hybrid

[RxJS] RefCount: automatically starting and stopping an execution

Angular 6 / Rxjs - 如何基础:observables 成功,错误,最后

如何理解 RxJS?RxJS的中文API和使用教程

rxjs-tslint vs rxjs-tslint-rules 包

RxJS 6有哪些新变化?