defaultIfEmpty.js 576 B

1234567891011121314151617
  1. import { operate } from '../util/lift';
  2. import { createOperatorSubscriber } from './OperatorSubscriber';
  3. export function defaultIfEmpty(defaultValue) {
  4. return operate((source, subscriber) => {
  5. let hasValue = false;
  6. source.subscribe(createOperatorSubscriber(subscriber, (value) => {
  7. hasValue = true;
  8. subscriber.next(value);
  9. }, () => {
  10. if (!hasValue) {
  11. subscriber.next(defaultValue);
  12. }
  13. subscriber.complete();
  14. }));
  15. });
  16. }
  17. //# sourceMappingURL=defaultIfEmpty.js.map