Created
May 14, 2016 23:41
-
-
Save griffinmichl/d87430e5451fc2d778d293d915de7b39 to your computer and use it in GitHub Desktop.
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 fetchContent = (url) => | |
rx.Observable.create(observer => | |
fetch(url) | |
.then(res => res.json()) | |
.then(json => { | |
observer.onNext(json) | |
observer.onCompleted() | |
) | |
.catch(e => observer.onError()) | |
) | |
const hover$ = rx.Observable.fromEvent(myButton, 'mouseover'); | |
const leave$ = rx.Observable.fromEvent(myButton, 'mouseout'); | |
const click$ = rx.Observable.fromEvent(myButton, 'click'); | |
const hoverRequest$ = hover$ | |
.flatMap(e => | |
fetchContent(e.target.href).takeUntil(leave$) | |
) | |
const displayData$ = click$ | |
.withLatestFrom(hoverRequest$) | |
.filter(([click, json]) => !!json) | |
.map(([click, json]) => json) | |
displayData$.subscribe(json => console.log(json)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment