使用打字稿在反应式中创建两个流以观察一次单击或两次单击

时间:2018-11-29 10:28:36

标签: typescript reactive-programming

我想做的是http://jsfiddle.net/staltz/4gGgs/27/,但要使用打字稿。

我已经达到以下目标:

const clickStream = fromEvent(document.getElementById('btnAction'), 'click');

const multiClickStream = clickStream.pipe(
  buffer(clickStream.pipe(throttle(ev => interval(250)))),
  map(list => list.length),
  filter(x => x >= 2)
);

const singleClickStream = clickStream.pipe(
  buffer(clickStream.pipe(throttle(ev => interval(250)))),
  map(list => list.length),
  filter(x => x === 1)
);

multiClickStream.subscribe(numClicks =>
  document.querySelector('h2').textContent =  `${numClicks}x click`
);

singleClickStream.subscribe(numClicks =>
  document.querySelector('h2').textContent =  `${numClicks}x click`
);

merge(singleClickStream, multiClickStream).pipe(
  throttle(ev => interval(1000))
);

//document.querySelector('h2').textContent = '';

我没有得到相同的结果

感谢您的帮助

0 个答案:

没有答案