Last active
October 14, 2015 00:51
-
-
Save findjashua/7afc9680892614c24ed9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 getObservableAndNext = (baseUrl, firstPage) => { | |
const subject = new Rx.Subject() | |
const response$ = subject | |
.flatMap(page => { return fetch(baseUrl, page) }) | |
.startsWith(firstPage) | |
const data$ = response.map(response) => { return response.data }) | |
const page$ = response$.map((response) => { return response.nextPage }) | |
const next = () => subject.onNext(page$.last()) | |
return { data$, next} | |
} | |
const { data$, next } = getObservableAndNext('base_url', 0) | |
data$.subscribe(data => { | |
process(data) | |
next() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment