Last active
May 13, 2018 07:11
-
-
Save cartant/1d3ae38bf08e3b2f88a027f2a3329fbd 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
| import { EMPTY, Observable, Subscription } from "rxjs"; | |
| import { concatMap, expand, map } from "rxjs/operators"; | |
| import { NotificationQueue } from "rxjs-etc"; | |
| import { get } from "./github"; | |
| function pages<T>( | |
| uri: string, | |
| notifier: Observable<any> | |
| ): Observable<T[]> { | |
| return new Observable<any>(observer => { | |
| const notificationQueue = new NotificationQueue(notifier); | |
| const subscription = new Subscription(); | |
| subscription.add(notificationQueue.connect()); | |
| subscription.add( | |
| get<T[]>(uri).pipe( | |
| expand(({ next }) => { | |
| if (next) { | |
| return notificationQueue.pipe( | |
| concatMap(() => get(next)) | |
| ); | |
| } | |
| return EMPTY; | |
| }), | |
| map(({ content }) => content) | |
| ).subscribe(observer) | |
| ); | |
| return subscription; | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment