exhaustMap.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Projects each source value to an Observable which is merged in the output
  6. * Observable only if the previous projected Observable has completed.
  7. *
  8. * <span class="informal">Maps each value to an Observable, then flattens all of
  9. * these inner Observables using {@link exhaust}.</span>
  10. *
  11. * <img src="./img/exhaustMap.png" width="100%">
  12. *
  13. * Returns an Observable that emits items based on applying a function that you
  14. * supply to each item emitted by the source Observable, where that function
  15. * returns an (so-called "inner") Observable. When it projects a source value to
  16. * an Observable, the output Observable begins emitting the items emitted by
  17. * that projected Observable. However, `exhaustMap` ignores every new projected
  18. * Observable if the previous projected Observable has not yet completed. Once
  19. * that one completes, it will accept and flatten the next projected Observable
  20. * and repeat this process.
  21. *
  22. * @example <caption>Run a finite timer for each click, only if there is no currently active timer</caption>
  23. * var clicks = fromEvent(document, 'click');
  24. * var result = clicks.pipe(exhaustMap((ev) => Rx.Observable.interval(1000).take(5)));
  25. * result.subscribe(x => console.log(x));
  26. *
  27. * @see {@link concatMap}
  28. * @see {@link exhaust}
  29. * @see {@link mergeMap}
  30. * @see {@link switchMap}
  31. *
  32. * @param {function(value: T, ?index: number): ObservableInput} project A function
  33. * that, when applied to an item emitted by the source Observable, returns an
  34. * Observable.
  35. * @return {Observable} An Observable containing projected Observables
  36. * of each item of the source, ignoring projected Observables that start before
  37. * their preceding Observable has completed.
  38. */
  39. function exhaustMap(project) {
  40. return operators_1.exhaustMap(project)(this);
  41. }
  42. exports.exhaustMap = exhaustMap;
  43. //# sourceMappingURL=exhaustMap.js.map