0

在 RxJS 4.0 中,我可以执行以下操作:

let clicks = Observable.fromEvent(board.canvas, 'click'),
    keydowns = Observable.fromEvent(document, 'keydown')
      .filter((e) => e.keyCode === 32);
  return Observable
    .merge(clicks, keydowns)
    .sample(200).
    .timestamp();

现在 RxJS 5.0 放弃了对timestamp.

4

2 回答 2

2

对于未来的读者 - .timestamp()已在 RxJS 5.0(在 beta.4 (2016-03-29))中重新实现。

变更日志:https ://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md

于 2016-09-13T07:36:40.650 回答
1

我们可以通过映射一些源 Observable 来相当容易地重新创建这种行为:

function timestamp(source) {
    return source.map(value => ({ value, timestamp: Date.now() }));
}

在您的代码中:

let clicks = Observable.fromEvent(board.canvas, 'click');
let keydowns = Observable.fromEvent(document, 'keydown')
      .filter((e) => e.keyCode === 32);

let clicksAndKeydowns = Observable
    .merge(clicks, keydowns)
    .sample(200);

return timestamp(clicksAndKeydowns);
于 2016-03-17T15:27:11.657 回答