两个例子
鼠标拖拽
let getElemenetDrags = el =>
el.mouseDowns
.map( mouseDown =>
document.mouseMoves
.takeUntil(document.mouseUps)
)
.concatAll()
getElementDrags(div)
.forEach(position => img.position = position )
搜索提示
let search =
keyPresses
.debounce(250) // 原文是 throttle,但我个人认为原文写错了,我已经在 Twitter 上询问了演讲者,尚未得到回复
.map(key =>
getJSON('/search?q=' + input.value)
.retry(3)
.takeUntil(keyPresses)
)
.concatAll()
search.forEach(
results => updateUI(results),
error => showMessage(error)
)
Rx.js思维方式
我的理解:把异步请求,用时间关联起来,异步操作转为数组操作
且不用担心内存泄露
演讲
英文教程:http://reactivex.io/learnrx/ (演讲者自己写的教程)
太郎:https://zhuanlan.zhihu.com/p/23331432