withLatestFrom.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /* tslint:enable:max-line-length */
  5. /**
  6. * Combines the source Observable with other Observables to create an Observable
  7. * whose values are calculated from the latest values of each, only when the
  8. * source emits.
  9. *
  10. * <span class="informal">Whenever the source Observable emits a value, it
  11. * computes a formula using that value plus the latest values from other input
  12. * Observables, then emits the output of that formula.</span>
  13. *
  14. * <img src="./img/withLatestFrom.png" width="100%">
  15. *
  16. * `withLatestFrom` combines each value from the source Observable (the
  17. * instance) with the latest values from the other input Observables only when
  18. * the source emits a value, optionally using a `project` function to determine
  19. * the value to be emitted on the output Observable. All input Observables must
  20. * emit at least one value before the output Observable will emit a value.
  21. *
  22. * @example <caption>On every click event, emit an array with the latest timer event plus the click event</caption>
  23. * var clicks = Rx.Observable.fromEvent(document, 'click');
  24. * var timer = Rx.Observable.interval(1000);
  25. * var result = clicks.withLatestFrom(timer);
  26. * result.subscribe(x => console.log(x));
  27. *
  28. * @see {@link combineLatest}
  29. *
  30. * @param {ObservableInput} other An input Observable to combine with the source
  31. * Observable. More than one input Observables may be given as argument.
  32. * @param {Function} [project] Projection function for combining values
  33. * together. Receives all values in order of the Observables passed, where the
  34. * first parameter is a value from the source Observable. (e.g.
  35. * `a.withLatestFrom(b, c, (a1, b1, c1) => a1 + b1 + c1)`). If this is not
  36. * passed, arrays will be emitted on the output Observable.
  37. * @return {Observable} An Observable of projected values from the most recent
  38. * values from each input Observable, or an array of the most recent values from
  39. * each input Observable.
  40. * @method withLatestFrom
  41. * @owner Observable
  42. */
  43. function withLatestFrom() {
  44. var args = [];
  45. for (var _i = 0; _i < arguments.length; _i++) {
  46. args[_i] = arguments[_i];
  47. }
  48. return operators_1.withLatestFrom.apply(void 0, args)(this);
  49. }
  50. exports.withLatestFrom = withLatestFrom;
  51. //# sourceMappingURL=withLatestFrom.js.map