When you complete a stream, there’s no way to restart it, you must resubscribe. This lesson shows how repeat comes in handy to resubscribe after a stream has completed.

Current this block of code:

const timer$ = starters$
.switchMap(intervalActions)
.startWith(data)
.scan((acc, curr)=> curr(acc)) timer$
.do((x)=> console.log(x))
.takeWhile((data)=> data.count <= )
.withLatestFrom(
input$.do((x)=> console.log(x)),
(timer, input)=> ({count: timer.count, text: input})
)
.filter((data)=> data.count === parseInt(data.text))
.reduce((acc, curr)=> acc + , )
.subscribe(
(x)=> console.log('Score', x),
err=> console.log(err),
()=> console.log('complete')
); /**
"Score"
0
"complete"
**/

Once it hit complete block, you can never start the timer again. THis is because the stream is completed, so if we want able to re-subscribe many times, we can use repeact() method:

timer$
.do((x)=> console.log(x))
.takeWhile((data)=> data.count <= )
.withLatestFrom(
input$.do((x)=> console.log(x)),
(timer, input)=> ({count: timer.count, text: input})
)
.filter((data)=> data.count === parseInt(data.text))
.reduce((acc, curr)=> acc + , )
.repeat() // repact the block of code above
.subscribe(
(x)=> console.log('Score', x),
err=> console.log(err),
()=> console.log('complete')
);

Now we are able to repact the stream, but it will never hit the complete block, but it is ok.

And also should be careful when use repeact(); you cannot put it anywhere you want, if you put it before fiilter(), then it willl never hit the filter block, so usually should put it right before the subscribe() method.

[RxJS] Resubscribing to a Stream with Repeat的更多相关文章

  1. [RxJS] Handling a Complete Stream with Reduce

    When a stream has completed, you often need to evaluate everything that has happened while the strea ...

  2. [RxJS] Toggle A Stream On And Off With RxJS

    This lesson covers how to toggle an observable on and off from another observable by showing how to ...

  3. [Recompose] Stream Props to React Children with RxJS

    You can decouple the parent stream Component from the mapped React Component by using props.children ...

  4. [Recompose] Stream a React Component from an Ajax Request with RxJS

    Loading data using RxJS is simple using Observable.ajax. This lesson shows you how to take the ajax ...

  5. [Recompose] Pass a React Prop to a Stream in RxJS

    When you declare your Component and Props in JSX, you can pass those props along to your RxJS stream ...

  6. [RxJS] Transformation operator: repeat

    Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...

  7. [RxJS] Stream Processing With RxJS vs Array Higher-Order Functions

    Higher order Array functions such as filter, map and reduce are great for functional programming, bu ...

  8. [RxJS] Logging a Stream with do()

    To help understand your stream, you’ll almost always want to log out some the intermediate values to ...

  9. [RxJS] Stopping a Stream with TakeUntil

    Observables often need to be stopped before they are completed. This lesson shows how to use takeUnt ...

随机推荐

  1. Win7 64位下配置Qt5.3和Wincap

         最近在学网络编程,想在windows下用Qt做个网络抓包工具,就要用到WinPcap,而我的电脑的系统是Win7 64位,qt版本是Qt 5.3.1 for Windows 64-bit ( ...

  2. RecyclerView 详解

    概述 RecyclerView出现已经有一段时间了,相信大家肯定不陌生了,大家可以通过导入support-v7对其进行使用.  据官方的介绍,该控件用于在有限的窗口中展示大量数据集,其实这样功能的控件 ...

  3. 【Linux常用命令(更新)】

    1.ifconfig:查看当前ip,网卡信息 2.df -h:查看文件系统的使用情况,挂载点信息 3.du -sh  /var:查看/var文件夹大小 4.netstat -a:查看网络联机状态 5. ...

  4. angularjs某些指令在外部作用域继承并创建新的子作用域引申出的“值复制”与“引用复制”的问题

    <!DOCTYPE html> <html lang="zh-CN" ng-app="app"> <head> <me ...

  5. hook技术分类

    1.HOOK SERVICE TABLE:HOOK SSDT 这种方法对于拦截 NATIVE API 来说用的比较多. SSDT hook,一句话——Windows把需要调用的内核API地址全都存在了 ...

  6. Chrome调试nodejs

    1.安装node-inspector 命令: npm install -g node-inspector 2.nodemon --debug xxx.js启动项目(如果使用--debug-brk 就会 ...

  7. jQuery 2.2 和 1.12 新版本发布

    新年新气象,jQuery 团队于昨日发布了两个新版本:1.12 和 2.2.这两个版本都包含了大量的Bug修正和功能改进.基本上这会是3.0之前最后一次发布.不过由于3.0不做向下兼容,所以届时 jQ ...

  8. javascript各种专业名词

    刚开始学javascript经常看到各种专业名词,在此整理一下个人的学习笔记: 直接量 直接量——就是程序中直接使用的数据值,如:88    //数字(String)"hello world ...

  9. WCF消息

    1. MessageContract 序列化一个对象并生成消息的时候,希望将部分数据成员作为SOAP的报头,部分作为消息的主体.比如说,我们有一个服务操作采用流的方式进行文件的上载,除了以流的方式传输 ...

  10. JNI错误记录--JNI程序调用本地库时JVM崩溃

    什么是JNI内存泄露,基本的避免方法 : http://www.ibm.com/developerworks/cn/java/j-lo-jnileak/ 最近的课题中需要用到Spark,同组同学负责的 ...