[RxJS] Use groupBy in real RxJS applications
This lesson will show when to apply groupBy in the real world. This RxJS operator is best suited when a source observable represents many data sources, e.g. an observable for multitouch events.
const busObservable = Rx.Observable.of(
{code: 'en-us', value: '-TEST-'},
{code: 'en-us', value: 'hello'},
{code: 'es', value: '-TEST-'},
{code: 'en-us', value: 'amazing'},
{code: 'pt-br', value: '-TEST-'},
{code: 'pt-br', value: 'olá'},
{code: 'es', value: 'hola'},
{code: 'es', value: 'mundo'},
{code: 'en-us', value: 'world'},
{code: 'pt-br', value: 'mundo'},
{code: 'es', value: 'asombroso'},
{code: 'pt-br', value: 'maravilhoso'}
).concatMap(x => Rx.Observable.of(x).delay()); const all = busObservable
.groupBy(obj => obj.code) // 2-d obs
.mergeMap(innerObs => innerObs.skip().map(obj => obj.value)); all.subscribe(x => console.log(x));
/*
"hello"
"amazing"
"olá"
"hola"
"mundo"
"world"
"mundo"
"asombroso"
"maravilhoso"
*/
- The 'groupBy' return a 2-d observable, can use 'switchMap' or 'mergeMap' to conver to 1-d observable.
[RxJS] Use groupBy in real RxJS applications的更多相关文章
- [RxJS + AngularJS] Sync Requests with RxJS and Angular
When you implement a search bar, the user can make several different queries in a row. With a Promis ...
- [RxJS] Refactoring Composable Streams in RxJS, switchMap()
Refactoring streams in RxJS is mostly moving pieces of smaller streams around. This lessons demonstr ...
- [RxJS] Reactive Programming - Why choose RxJS?
RxJS is super when dealing with the dynamic value. Let's see an example which not using RxJS: var a ...
- [RxJS] Learn How To Use RxJS 5.5 Beta 2
The main changes is about how you import rxjs opreators from now on. And introduce lettable opreator ...
- [rxjs] Creating An Observable with RxJS
Create an observable var Observable = Rx.Observable; var source = Observable.create(function(observe ...
- [RxJS] Reactive Programming - What is RxJS?
First thing need to understand is, Reactive programming is dealing with the event stream. Event stre ...
- [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 ...
- [转]VS Code 扩展 Angular 6 Snippets - TypeScript, Html, Angular Material, ngRx, RxJS & Flex Layout
本文转自:https://marketplace.visualstudio.com/items?itemName=Mikael.Angular-BeastCode VSCode Angular Typ ...
- rxjs的世界
rxjs学习了几个月了,看了大量的东西,在理解Observable的本文借鉴的是渔夫的故事,原文,知识的主线以<深入浅出rxjs>为主,动图借鉴了rxjs中文社区翻译的文章和国外的一个动图 ...
随机推荐
- 趣闻|Python之禅(The Zen of Python)
在Python解释器中输入“import this”会发生什么?如果你不知道这个彩蛋,推荐继续阅读这篇文章. 2001年秋,Foretec(一家会议组织公司)正在准备召开第十届Internationa ...
- 【Codeforces Round #455 (Div. 2) B】Segments
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 处理出所有的线 其实就是区间. 总共有n*(n+1)/2个 然后按照左端点.右端点排序 每次取最左边的线. 多种可能就取右端点尽量小 ...
- 解决Cookie乱码
在Asp.net的HttpCookie中写入汉字,读取值为什么全是乱码?其实这是因 为文字编码而造成的,汉字是两个编码,所以才会搞出这么个乱码出来!其实解决的方法很简单:只要在写入Cookie时,先将 ...
- rhel5安装 oracle10
readhat 安装11gr2文档 需要注意的地方:必须关掉的 1,防火墙:2,SElinux . root 用户运行 setup 命令可关防火墙与SElinux 修改网络配置文件,一定要重启此文 ...
- 利用mysql5.6 的st_distance 实现按照距离远近排序。 (转载)
http://blog.csdn.net/zhouzhiwengang/article/details/53612481
- UVA - 590Always on the run(递推)
题目:UVA - 590Always on the run(递推) 题目大意:有一个小偷如今在计划着逃跑的路线,可是又想省机票费. 他刚開始在城市1,必须K天都在这N个城市里跑来跑去.最后一天达到城市 ...
- 以流的形式接收Http请求
IEnumerable<ReportObject> IHttpReceiveReport.OnPost(System.Web.HttpContextBase context) { //[{ ...
- What is corresponding Cron expression to fire in every X seconds, where X > 60? --转载
原文地址:http://stackoverflow.com/questions/2996280/what-is-corresponding-cron-expression-to-fire-in-eve ...
- winform中comboBox控件加默认选项的问题
winform程序设计中,label,TextBox,ComboBox等几个控件几乎是用得最多的,在设计中经常会遇到一些小问题,如:comboBox控件绑定了数据源之后,如何设置默认值? combob ...
- stm32关于.o的错误
是因为没有加入官方库的原因,而且编译出错之后不能跳转到那里.