Skip to content

Instantly share code, notes, and snippets.

@edulan
Created November 28, 2017 18:07
Show Gist options
  • Save edulan/c8af4dd16818d3881fa064116d3e70d8 to your computer and use it in GitHub Desktop.
Save edulan/c8af4dd16818d3881fa064116d3e70d8 to your computer and use it in GitHub Desktop.
Rx take latest
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