1f836308bda95565a6fe08a5be2540304db44c3f8969ef8ae06b9f4f9f8e9e6adbd31a77690661ffbf6a1886ac9d4e866459eebc67ca2a8dacd1b0685684ef 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { 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. */
  37. export declare function defaultIfEmpty<T, R>(defaultValue: R): OperatorFunction<T, T | R>;
  38. //# sourceMappingURL=defaultIfEmpty.d.ts.map