Example RxJS Observable when mouse or click activity Re-starts

夙愿已清 提交于 2019-12-04 21:32:12

You could use something like this:

var restart$ = Rx.Observable.of('Kick off')
  .merge(lastact$)
  .mergeMap(() => allactivity$.skipUntil(lastact$).first());

Explanation

  • Rx.Observable.of('Kick off') - Once in the beginning, ...
  • .merge(lastact$) - and for everytime lastact$ emits, ...
  • .mergeMap(() => ...) - create an observable ...
  • allactivity$ - that will observe on allactivity$ for all items...
  • .skipUntil(lastact$) - since the firstlastact$ emission (after the creation of this observable) ...
  • .first() - and take only the first item (that is, the first activity happen after the lastact$ emit)

Edit:

The above observable will not trigger on the first mouse move, to handle that:

var firstMoveAndRestart$ = restart$.merge(allactivity$.first());
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!