Front end of the Slack clone application.

switchMapTo.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { switchMapTo as higherOrder } from '../operators/switchMapTo';
  2. /* tslint:enable:max-line-length */
  3. /**
  4. * Projects each source value to the same Observable which is flattened multiple
  5. * times with {@link switch} in the output Observable.
  6. *
  7. * <span class="informal">It's like {@link switchMap}, but maps each value
  8. * always to the same inner Observable.</span>
  9. *
  10. * <img src="./img/switchMapTo.png" width="100%">
  11. *
  12. * Maps each source value to the given Observable `innerObservable` regardless
  13. * of the source value, and then flattens those resulting Observables into one
  14. * single Observable, which is the output Observable. The output Observables
  15. * emits values only from the most recently emitted instance of
  16. * `innerObservable`.
  17. *
  18. * @example <caption>Rerun an interval Observable on every click event</caption>
  19. * var clicks = Rx.Observable.fromEvent(document, 'click');
  20. * var result = clicks.switchMapTo(Rx.Observable.interval(1000));
  21. * result.subscribe(x => console.log(x));
  22. *
  23. * @see {@link concatMapTo}
  24. * @see {@link switch}
  25. * @see {@link switchMap}
  26. * @see {@link mergeMapTo}
  27. *
  28. * @param {ObservableInput} innerObservable An Observable to replace each value from
  29. * the source Observable.
  30. * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
  31. * A function to produce the value on the output Observable based on the values
  32. * and the indices of the source (outer) emission and the inner Observable
  33. * emission. The arguments passed to this function are:
  34. * - `outerValue`: the value that came from the source
  35. * - `innerValue`: the value that came from the projected Observable
  36. * - `outerIndex`: the "index" of the value that came from the source
  37. * - `innerIndex`: the "index" of the value from the projected Observable
  38. * @return {Observable} An Observable that emits items from the given
  39. * `innerObservable` (and optionally transformed through `resultSelector`) every
  40. * time a value is emitted on the source Observable, and taking only the values
  41. * from the most recently projected inner Observable.
  42. * @method switchMapTo
  43. * @owner Observable
  44. */
  45. export function switchMapTo(innerObservable, resultSelector) {
  46. return higherOrder(innerObservable, resultSelector)(this);
  47. }
  48. //# sourceMappingURL=switchMapTo.js.map