UNPKG

1.05 kBPlain TextView Raw
1import { Observable } from 'rxjs';
2import { repeatWhen as higherOrder } from 'rxjs/operators';
3
4/**
5 * Returns an Observable that mirrors the source Observable with the exception of a `complete`. If the source
6 * Observable calls `complete`, this method will emit to the Observable returned from `notifier`. If that Observable
7 * calls `complete` or `error`, then this method will call `complete` or `error` on the child subscription. Otherwise
8 * this method will resubscribe to the source Observable.
9 *
10 * <img src="./img/repeatWhen.png" width="100%">
11 *
12 * @param {function(notifications: Observable): Observable} notifier - Receives an Observable of notifications with
13 * which a user can `complete` or `error`, aborting the repetition.
14 * @return {Observable} The source Observable modified with repeat logic.
15 * @method repeatWhen
16 * @owner Observable
17 */
18export function repeatWhen<T>(this: Observable<T>, notifier: (notifications: Observable<any>) => Observable<any>): Observable<T> {
19 return higherOrder(notifier)(this) as Observable<T>;
20}