Skip to content

Instantly share code, notes, and snippets.

@findjashua
Last active October 14, 2015 00:51
Show Gist options
  • Save findjashua/7afc9680892614c24ed9 to your computer and use it in GitHub Desktop.
Save findjashua/7afc9680892614c24ed9 to your computer and use it in GitHub Desktop.
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