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.

最新文章

  1. css3 FlexBox 弹性布局
  2. 添加系统右键菜单项 管理员取得所有权(W)(带盾牌)
  3. 浅谈对ionic项目的理解
  4. simple_html_dom配合snoopy使用
  5. 第一课JAVA开发环境配置
  6. JQuery事件与应用(一)
  7. django(二)视图和URL配置
  8. 使用python/casperjs编写终极爬虫-客户端App的抓取-ZOL技术频道
  9. 如何将 MFC ActiveX 控件标记为安全,脚本和初始化
  10. CSS常用字体名称
  11. Ionic生命周期与注意点
  12. 蚂蚁金服 Service Mesh 渐进式迁移方案|Service Mesh Meetup 实录
  13. NOIP模拟赛-2018.11.5
  14. vim_action
  15. LOCAL_SHARED_LIBRARIES 与 LOCAL_LDLIBS,LOCAL_LDFLAGS的区别
  16. P2770 航空路线问题
  17. Python学习-day14-HTML
  18. Unity学习之路——C#相关
  19. 小试JVM工具
  20. hadoop wordcount程序缺陷

热门文章

  1. Dialog( 对话框) 组件
  2. MYSQL触发器的NEW和OLD的一个小问题
  3. javascript 字符串转为对像函数eval(&quot;string&quot;)
  4. mybatis常用语句
  5. discuz3.2x增加邮箱验证功能
  6. bootstrapValidator Maximum call stack size exceeded
  7. 很强的PHP图片处理类
  8. text-align:justify小例子
  9. Python 基础教程中的问题及解决方案(1)
  10. JS 闭包问题