While frameworks like Angular 2 and CycleJS provides great ways to update the DOM and handle subscriptions for you, this lesson shows how you can still do basic subscribe blocks and manually update the DOM on your own.

const Observable = Rx.Observable;

const startButton = document.querySelector('#start');
const halfButton = document.querySelector('#half');
const quarterButton = document.querySelector('#quarter'); const stopButton = document.querySelector('#stop');
const resetButton = document.querySelector('#reset'); const input = document.querySelector('#input'); const start$ = Observable.fromEvent(startButton, 'click');
const half$ = Observable.fromEvent(halfButton, 'click');
const quarter$ = Observable.fromEvent(quarterButton, 'click'); const stop$ = Observable.fromEvent(stopButton, 'click');
const reset$ = Observable.fromEvent(resetButton, 'click'); const input$ = Observable.fromEvent(input, 'input')
.map(event => event.target.value); const data = {count:};
const inc = (acc)=> ({count: acc.count + });
const reset = (acc)=> data; const starters$ = Observable.merge(
start$.mapTo(),
half$.mapTo(),
quarter$.mapTo()
); const intervalActions = (time)=> Observable.merge(
Observable.interval(time)
.takeUntil(stop$).mapTo(inc),
reset$.mapTo(reset)
); 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 + , )
.repeat()
.subscribe(
(x)=> document.querySelector('#score').innerHTML = `
${x}
`,
err=> console.log(err),
()=> console.log('complete')
);

[RxJS] Basic DOM Rendering with Subscribe的更多相关文章

  1. [RxJS] Reactive Programming - Rendering on the DOM with RxJS

    <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery- ...

  2. [RxJS] Returning subscriptions from the subscribe function

    So far, when writing these subscribe functions, we haven't returned anything. It is possible return ...

  3. [Javascript + rxjs] Simple drag and drop with Observables

    Armed with the map and concatAll functions, we can create fairly complex interactions in a simple wa ...

  4. DOJO DOM 功能

    In this tutorial, you'll learn about how to use Dojo to manipulate the DOM in a simple, cross-browse ...

  5. [RxJS] AsyncSubject

    AsyncSubject emit the last value of a sequence only if the sequence completed. This value is then ca ...

  6. rxjs 常用的静态操作符

    操作符文档 API create const { Observable } = require('rxjs'); // 创建 Observables var observable = Observab ...

  7. [Redux-Observable && Unit Testing] Use tests to verify updates to the Redux store (rxjs scheduler)

    In certain situations, you care more about the final state of the redux store than you do about the ...

  8. RxJS——可观察的对象(Observable)

    可观察的(Observable) 可观察集合(Observables)是多值懒推送集合.它们填补了下面表格的空白: SINGLE MULTIPLE Pull Function Iterator Pus ...

  9. angularjs学习总结 详细教程(转载)

    1 前言 前端技术的发展是如此之快,各种优秀技术.优秀框架的出现简直让人目不暇接,紧跟时代潮流,学习掌握新知识自然是不敢怠慢. AngularJS是google在维护,其在国外已经十分火热,可是国内的 ...

随机推荐

  1. 关于IE6幽灵字体

    前言:今天做项目的时候在IE6下出现了这样的一种现像,这种情况只在IE6下出现,最后在网友的帮助下这个问题最终得到了解决.所以马上作了下笔记! 情况如下图: 我在网上找了点资料出现IE6下幽灵字体的情 ...

  2. web开发小白之路

    今天就来谈谈本人从事web开发的一系列白只又白的经历,本人刚开始是从事ios开发的,由于一系列的变故现在变为了web前端开发,不过说来也奇怪,刚开始接触前端时间可以说是彻底蒙圈,各种选择器,各种适配搞 ...

  3. [serverlet][转载: 深入理解HTTP Session]

    [serverlet][转载: 深入理解HTTP Session] 标签(空格分隔): 未分类 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任. ...

  4. 在Ubuntu下的Apache上建立新的website,以及enable mono

    1. 在Apache下建立新的web site a. $>cd /etc/apache2/ b. $>vi ports.conf 填加Listen 8090(注意不要打开8080,因为To ...

  5. (转)检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(转)

    我们将ASP.NET程序从IIS6移植到IIS7,可能运行提示以下错误: HTTP 错误 500.23 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.N ...

  6. Android-操作栏之选项菜单

    回答第一个问题:什么是选项菜单?答:选项菜单就是可以显示在操作栏上的菜单. 菜单的视图需要建立在res/menu下. 其中,showAsAction属性用于指定菜单选项是显示在操作栏还是隐藏到溢出菜单 ...

  7. shell中对于命令的搜寻顺序

    当你在shell命令行输入一条命令时,shell的搜寻顺序是如何的呢?当你的脚本名字和shell中的函数名字重名,shell是如何决定运行哪一个的? 在shell中,shell对于命令的搜寻优先级为: ...

  8. java实现双向链表

    PS:双向链表(每个节点含有指向前一个节点的前驱与后一个节点的后继) public class DoublyLinkedList { static class Node { private Objec ...

  9. Bash 使用技巧大补贴

    https://linuxtoy.org/archives/the-best-tips-and-tricks-for-bash.html

  10. 吃午饭前,按书上的代码写会儿--Hunt the Wumpus第一个版本

    有空就要慢慢练起~~~~脑袋动起来是很快乐的事儿....:) <易学PYTHON>演练一遍. from random import choice cave_numbers = range( ...