Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

defaultIfEmpty.js 914B

123456789101112131415161718192021222324252627282930
  1. import { Subscriber } from '../Subscriber';
  2. export function defaultIfEmpty(defaultValue = null) {
  3. return (source) => source.lift(new DefaultIfEmptyOperator(defaultValue));
  4. }
  5. class DefaultIfEmptyOperator {
  6. constructor(defaultValue) {
  7. this.defaultValue = defaultValue;
  8. }
  9. call(subscriber, source) {
  10. return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));
  11. }
  12. }
  13. class DefaultIfEmptySubscriber extends Subscriber {
  14. constructor(destination, defaultValue) {
  15. super(destination);
  16. this.defaultValue = defaultValue;
  17. this.isEmpty = true;
  18. }
  19. _next(value) {
  20. this.isEmpty = false;
  21. this.destination.next(value);
  22. }
  23. _complete() {
  24. if (this.isEmpty) {
  25. this.destination.next(this.defaultValue);
  26. }
  27. this.destination.complete();
  28. }
  29. }
  30. //# sourceMappingURL=defaultIfEmpty.js.map