a zip code crypto-currency system good for red ONLY

switchMap.js 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { switchMap as higherOrderSwitchMap } from '../operators/switchMap';
  2. /* tslint:enable:max-line-length */
  3. /**
  4. * Projects each source value to an Observable which is merged in the output
  5. * Observable, emitting values only from the most recently projected Observable.
  6. *
  7. * <span class="informal">Maps each value to an Observable, then flattens all of
  8. * these inner Observables using {@link switch}.</span>
  9. *
  10. * <img src="./img/switchMap.png" width="100%">
  11. *
  12. * Returns an Observable that emits items based on applying a function that you
  13. * supply to each item emitted by the source Observable, where that function
  14. * returns an (so-called "inner") Observable. Each time it observes one of these
  15. * inner Observables, the output Observable begins emitting the items emitted by
  16. * that inner Observable. When a new inner Observable is emitted, `switchMap`
  17. * stops emitting items from the earlier-emitted inner Observable and begins
  18. * emitting items from the new one. It continues to behave like this for
  19. * subsequent inner Observables.
  20. *
  21. * @example <caption>Rerun an interval Observable on every click event</caption>
  22. * var clicks = Rx.Observable.fromEvent(document, 'click');
  23. * var result = clicks.switchMap((ev) => Rx.Observable.interval(1000));
  24. * result.subscribe(x => console.log(x));
  25. *
  26. * @see {@link concatMap}
  27. * @see {@link exhaustMap}
  28. * @see {@link mergeMap}
  29. * @see {@link switch}
  30. * @see {@link switchMapTo}
  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. * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
  36. * A function to produce the value on the output Observable based on the values
  37. * and the indices of the source (outer) emission and the inner Observable
  38. * emission. The arguments passed to this function are:
  39. * - `outerValue`: the value that came from the source
  40. * - `innerValue`: the value that came from the projected Observable
  41. * - `outerIndex`: the "index" of the value that came from the source
  42. * - `innerIndex`: the "index" of the value from the projected Observable
  43. * @return {Observable} An Observable that emits the result of applying the
  44. * projection function (and the optional `resultSelector`) to each item emitted
  45. * by the source Observable and taking only the values from the most recently
  46. * projected inner Observable.
  47. * @method switchMap
  48. * @owner Observable
  49. */
  50. export function switchMap(project, resultSelector) {
  51. return higherOrderSwitchMap(project, resultSelector)(this);
  52. }
  53. //# sourceMappingURL=switchMap.js.map