Created
November 28, 2017 18:07
-
-
Save edulan/c8af4dd16818d3881fa064116d3e70d8 to your computer and use it in GitHub Desktop.
Rx take latest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const simulateTask = () => new Promise((resolve) => (setTimeout(resolve, Math.random() * 1E3 + 500))) | |
const click$ = Rx.Observable | |
.fromEvent(document, 'click') | |
.scan((clickCount) => clickCount + 1, 0) | |
click$.switchMap( | |
() => Rx.Observable.fromPromise(simulateTask()), | |
(clickCount) => clickCount | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment