【发布时间】:2016-01-20 01:34:27
【问题描述】:
我是 Rx.js 的新手,正在寻找有关 FRP 概念的一些基本帮助。我有一个使用generateWithRelativeTime 的流来保持游戏循环运行,还有一个流可以跟踪屏幕分辨率。我当前代码的问题是我的游戏循环仅在我的屏幕分辨率更改时运行。
我的模型函数生成的流需要 res$ 的最新值。
function model(res$) {
return res$.map(res => {
const rows = ceil(res[1] / CELL.HEIGHT)+1
const cols = ceil(res[0] / CELL.WIDTH)+1
return Observable.generateWithRelativeTime(
initWorld(rows, cols, 1.618),
noOp,
world => step(world),
noOp,
_ => 100,
Rx.Scheduler.requestAnimationFrame
).timeInterval()
});
}
function intent() {
return Observable.fromEvent(window, 'resize')
.map(e => [e.currentTarget.innerWidth, e.currentTarget.innerHeight])
.debounce(100, Rx.Scheduler.requestAnimationFrame)
.startWith([window.innerWidth, window.innerHeight])
}
model(intent())
【问题讨论】:
标签: javascript system.reactive reactive-programming rxjs frp