[RxJS] Basic DOM Rendering with Subscribe
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的更多相关文章
- [RxJS] Reactive Programming - Rendering on the DOM with RxJS
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery- ...
- [RxJS] Returning subscriptions from the subscribe function
So far, when writing these subscribe functions, we haven't returned anything. It is possible return ...
- [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 ...
- DOJO DOM 功能
In this tutorial, you'll learn about how to use Dojo to manipulate the DOM in a simple, cross-browse ...
- [RxJS] AsyncSubject
AsyncSubject emit the last value of a sequence only if the sequence completed. This value is then ca ...
- rxjs 常用的静态操作符
操作符文档 API create const { Observable } = require('rxjs'); // 创建 Observables var observable = Observab ...
- [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 ...
- RxJS——可观察的对象(Observable)
可观察的(Observable) 可观察集合(Observables)是多值懒推送集合.它们填补了下面表格的空白: SINGLE MULTIPLE Pull Function Iterator Pus ...
- angularjs学习总结 详细教程(转载)
1 前言 前端技术的发展是如此之快,各种优秀技术.优秀框架的出现简直让人目不暇接,紧跟时代潮流,学习掌握新知识自然是不敢怠慢. AngularJS是google在维护,其在国外已经十分火热,可是国内的 ...
随机推荐
- 数据持久化之CoreData
再次回归博客园, 已经实属不易了, 面临这近期忙忙碌碌的项目开发, 虽然并不是完全的没有闲暇时间, 但是怎么说呢, 也有着各种的无奈与曲折, 面临这产品需求的不断变化和页面的不断更新, 对于一个程序员 ...
- ARM Cortex-M
振荡周期.时钟周期.机器周期.指令周期 一个机器周期包含12个振荡周期或6个时钟周期 指令的执行时间称作指令周期(单.双.四周期) (1)振荡周期 振荡周期指为单片机提供定时信号的振荡源的 ...
- 解决MacOS Terminal打开慢的问题
用了Mac有一段时间了,突然发现Terminal打开奇慢,每次打开都显示logining...,打开大概要个五六秒的时间,以前打开都是瞬间打开的啊,这对于我们这种追求速度的程序员怎么受的了呢.开始一直 ...
- JSON.parse(),JSON.stringify(),jQuery.parseJSON()的用法
1. JSON.parse(jsonString): 在一个字符串中解析出JSON对象 var str = '[{"href":"baidu.com",&quo ...
- 读书笔记_Effective_C++_条款十七:以独立语句将new产生的对象置入智能指针
int get_int(); void f(shared_ptr<int> a, int); //下面调用 f(new int(3), get_int());//如果是类而不是int就可以 ...
- linux 进程备忘
进程间同步互斥方式: 1.管道pipe(亲属进程适用),命名管道fifopipe 2.信号量 3.共享内存配合信号量
- nodejs安装过程及视频地址
说实话在安装的过程中遇到了很多问题,包括npm install connect出错,主要是我之前安装了0.10版本之后安装4.X版本造成的,后面卸载没有卸载完全造成的,后面也就好了,网上说了很多重新设 ...
- 针对AJAX与JSONP的异同
针对AJAX与JSONP的异同 1.ajax和jsonp这两种技术在调用方式上“看起来”很像,目的也一样,都是请求一个url,然后把服务器返回的数据进行处理,因此jquery和ext等框架 ...
- mysql foreign key 外键
ALTER TABLE `fd_rel_customer_doctor` ADD CONSTRAINT `FK_fd_rel_customer_doctor_1` FOREIGN KEY (`CUST ...
- ECSTORE2.0 下载 (变量标签)
条目 用途 备注 coupon.mc.use_times 优惠券可用次数 - security.guest.enabled 是否支持非会员购物 - site.version version的最后修改时 ...