UNPKG

1.41 kBTypeScriptView Raw
1import { OperatorFunction } from '../types';
2/**
3 * Emits a given value if the source Observable completes without emitting any
4 * `next` value, otherwise mirrors the source Observable.
5 *
6 * <span class="informal">If the source Observable turns out to be empty, then
7 * this operator will emit a default value.</span>
8 *
9 * ![](defaultIfEmpty.png)
10 *
11 * `defaultIfEmpty` emits the values emitted by the source Observable or a
12 * specified default value if the source Observable is empty (completes without
13 * having emitted any `next` value).
14 *
15 * ## Example
16 *
17 * If no clicks happen in 5 seconds, then emit 'no clicks'
18 *
19 * ```ts
20 * import { fromEvent, takeUntil, interval, defaultIfEmpty } from 'rxjs';
21 *
22 * const clicks = fromEvent(document, 'click');
23 * const clicksBeforeFive = clicks.pipe(takeUntil(interval(5000)));
24 * const result = clicksBeforeFive.pipe(defaultIfEmpty('no clicks'));
25 * result.subscribe(x => console.log(x));
26 * ```
27 *
28 * @see {@link empty}
29 * @see {@link last}
30 *
31 * @param defaultValue The default value used if the source
32 * Observable is empty.
33 * @return A function that returns an Observable that emits either the
34 * specified `defaultValue` if the source Observable emits no items, or the
35 * values emitted by the source Observable.
36 */
37export declare function defaultIfEmpty<T, R>(defaultValue: R): OperatorFunction<T, T | R>;
38//# sourceMappingURL=defaultIfEmpty.d.ts.map
\No newline at end of file