PATH:
usr
/
local
/
lib
/
node_modules
/
ghost-cli
/
node_modules
/
rxjs
/
src
/
internal
/
operators
import { Operator } from '../Operator'; import { Observable } from '../Observable'; import { Subscriber } from '../Subscriber'; import { OperatorFunction, MonoTypeOperatorFunction } from '../types'; /* tslint:disable:max-line-length */ export function defaultIfEmpty<T>(defaultValue?: T): MonoTypeOperatorFunction<T>; export function defaultIfEmpty<T, R>(defaultValue?: R): OperatorFunction<T, T | R>; /* tslint:enable:max-line-length */ /** * Emits a given value if the source Observable completes without emitting any * `next` value, otherwise mirrors the source Observable. * * <span class="informal">If the source Observable turns out to be empty, then * this operator will emit a default value.</span> * *  * * `defaultIfEmpty` emits the values emitted by the source Observable or a * specified default value if the source Observable is empty (completes without * having emitted any `next` value). * * ## Example * If no clicks happen in 5 seconds, then emit "no clicks" * ```ts * import { fromEvent } from 'rxjs'; * import { defaultIfEmpty, takeUntil } from 'rxjs/operators'; * * const clicks = fromEvent(document, 'click'); * const clicksBeforeFive = clicks.pipe(takeUntil(interval(5000))); * const result = clicksBeforeFive.pipe(defaultIfEmpty('no clicks')); * result.subscribe(x => console.log(x)); * ``` * * @see {@link empty} * @see {@link last} * * @param {any} [defaultValue=null] The default value used if the source * Observable is empty. * @return {Observable} An Observable that emits either the specified * `defaultValue` if the source Observable emits no items, or the values emitted * by the source Observable. * @method defaultIfEmpty * @owner Observable */ export function defaultIfEmpty<T, R>(defaultValue: R = null): OperatorFunction<T, T | R> { return (source: Observable<T>) => source.lift(new DefaultIfEmptyOperator(defaultValue)) as Observable<T | R>; } class DefaultIfEmptyOperator<T, R> implements Operator<T, T | R> { constructor(private defaultValue: R) { } call(subscriber: Subscriber<T | R>, source: any): any { return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue)); } } /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ class DefaultIfEmptySubscriber<T, R> extends Subscriber<T> { private isEmpty: boolean = true; constructor(destination: Subscriber<T | R>, private defaultValue: R) { super(destination); } protected _next(value: T): void { this.isEmpty = false; this.destination.next(value); } protected _complete(): void { if (this.isEmpty) { this.destination.next(this.defaultValue); } this.destination.complete(); } }
[-] toArray.ts
[edit]
[-] window.ts
[edit]
[-] retry.ts
[edit]
[-] mergeAll.ts
[edit]
[-] windowWhen.ts
[edit]
[-] every.ts
[edit]
[-] timeout.ts
[edit]
[-] debounceTime.ts
[edit]
[-] index.ts
[edit]
[-] takeWhile.ts
[edit]
[-] audit.ts
[edit]
[-] reduce.ts
[edit]
[-] mapTo.ts
[edit]
[-] count.ts
[edit]
[-] debounce.ts
[edit]
[-] throwIfEmpty.ts
[edit]
[-] auditTime.ts
[edit]
[-] scan.ts
[edit]
[-] switchAll.ts
[edit]
[-] map.ts
[edit]
[-] bufferCount.ts
[edit]
[-] mergeScan.ts
[edit]
[-] publish.ts
[edit]
[-] min.ts
[edit]
[+]
..
[-] publishReplay.ts
[edit]
[-] bufferTime.ts
[edit]
[-] share.ts
[edit]
[-] repeat.ts
[edit]
[-] distinct.ts
[edit]
[-] concatMapTo.ts
[edit]
[-] buffer.ts
[edit]
[-] concatMap.ts
[edit]
[-] max.ts
[edit]
[-] partition.ts
[edit]
[-] observeOn.ts
[edit]
[-] bufferWhen.ts
[edit]
[-] dematerialize.ts
[edit]
[-] throttle.ts
[edit]
[-] groupBy.ts
[edit]
[-] withLatestFrom.ts
[edit]
[-] exhaust.ts
[edit]
[-] exhaustMap.ts
[edit]
[-] retryWhen.ts
[edit]
[-] zipAll.ts
[edit]
[-] find.ts
[edit]
[-] mergeMap.ts
[edit]
[-] single.ts
[edit]
[-] last.ts
[edit]
[-] combineLatest.ts
[edit]
[-] publishLast.ts
[edit]
[-] pluck.ts
[edit]
[-] pairwise.ts
[edit]
[-] distinctUntilChanged.ts
[edit]
[-] timeInterval.ts
[edit]
[-] shareReplay.ts
[edit]
[-] skipUntil.ts
[edit]
[-] findIndex.ts
[edit]
[-] windowToggle.ts
[edit]
[-] startWith.ts
[edit]
[-] timeoutWith.ts
[edit]
[-] concat.ts
[edit]
[-] materialize.ts
[edit]
[-] timestamp.ts
[edit]
[-] onErrorResumeNext.ts
[edit]
[-] subscribeOn.ts
[edit]
[-] takeUntil.ts
[edit]
[-] skipLast.ts
[edit]
[-] throttleTime.ts
[edit]
[-] mergeMapTo.ts
[edit]
[-] multicast.ts
[edit]
[-] merge.ts
[edit]
[-] takeLast.ts
[edit]
[-] delayWhen.ts
[edit]
[-] sampleTime.ts
[edit]
[-] tap.ts
[edit]
[-] take.ts
[edit]
[-] sample.ts
[edit]
[-] filter.ts
[edit]
[-] skip.ts
[edit]
[-] expand.ts
[edit]
[-] publishBehavior.ts
[edit]
[-] sequenceEqual.ts
[edit]
[-] ignoreElements.ts
[edit]
[-] catchError.ts
[edit]
[-] endWith.ts
[edit]
[-] refCount.ts
[edit]
[-] windowCount.ts
[edit]
[-] defaultIfEmpty.ts
[edit]
[-] windowTime.ts
[edit]
[-] switchMapTo.ts
[edit]
[-] switchMap.ts
[edit]
[-] delay.ts
[edit]
[-] bufferToggle.ts
[edit]
[-] repeatWhen.ts
[edit]
[-] concatAll.ts
[edit]
[-] first.ts
[edit]
[-] zip.ts
[edit]
[-] elementAt.ts
[edit]
[-] skipWhile.ts
[edit]
[-] race.ts
[edit]
[-] finalize.ts
[edit]
[-] combineAll.ts
[edit]
[-] distinctUntilKeyChanged.ts
[edit]
[-] isEmpty.ts
[edit]