Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

throwIfEmpty.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { EmptyError } from '../util/EmptyError';
  2. import { Subscriber } from '../Subscriber';
  3. export function throwIfEmpty(errorFactory = defaultErrorFactory) {
  4. return (source) => {
  5. return source.lift(new ThrowIfEmptyOperator(errorFactory));
  6. };
  7. }
  8. class ThrowIfEmptyOperator {
  9. constructor(errorFactory) {
  10. this.errorFactory = errorFactory;
  11. }
  12. call(subscriber, source) {
  13. return source.subscribe(new ThrowIfEmptySubscriber(subscriber, this.errorFactory));
  14. }
  15. }
  16. class ThrowIfEmptySubscriber extends Subscriber {
  17. constructor(destination, errorFactory) {
  18. super(destination);
  19. this.errorFactory = errorFactory;
  20. this.hasValue = false;
  21. }
  22. _next(value) {
  23. this.hasValue = true;
  24. this.destination.next(value);
  25. }
  26. _complete() {
  27. if (!this.hasValue) {
  28. let err;
  29. try {
  30. err = this.errorFactory();
  31. }
  32. catch (e) {
  33. err = e;
  34. }
  35. this.destination.error(err);
  36. }
  37. else {
  38. return this.destination.complete();
  39. }
  40. }
  41. }
  42. function defaultErrorFactory() {
  43. return new EmptyError();
  44. }
  45. //# sourceMappingURL=throwIfEmpty.js.map