Front end of the Slack clone application.

expand.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /** PURE_IMPORTS_START .._operators_expand PURE_IMPORTS_END */
  2. import { expand as higherOrder } from '../operators/expand';
  3. /* tslint:enable:max-line-length */
  4. /**
  5. * Recursively projects each source value to an Observable which is merged in
  6. * the output Observable.
  7. *
  8. * <span class="informal">It's similar to {@link mergeMap}, but applies the
  9. * projection function to every source value as well as every output value.
  10. * It's recursive.</span>
  11. *
  12. * <img src="./img/expand.png" width="100%">
  13. *
  14. * Returns an Observable that emits items based on applying a function that you
  15. * supply to each item emitted by the source Observable, where that function
  16. * returns an Observable, and then merging those resulting Observables and
  17. * emitting the results of this merger. *Expand* will re-emit on the output
  18. * Observable every source value. Then, each output value is given to the
  19. * `project` function which returns an inner Observable to be merged on the
  20. * output Observable. Those output values resulting from the projection are also
  21. * given to the `project` function to produce new output values. This is how
  22. * *expand* behaves recursively.
  23. *
  24. * @example <caption>Start emitting the powers of two on every click, at most 10 of them</caption>
  25. * var clicks = Rx.Observable.fromEvent(document, 'click');
  26. * var powersOfTwo = clicks
  27. * .mapTo(1)
  28. * .expand(x => Rx.Observable.of(2 * x).delay(1000))
  29. * .take(10);
  30. * powersOfTwo.subscribe(x => console.log(x));
  31. *
  32. * @see {@link mergeMap}
  33. * @see {@link mergeScan}
  34. *
  35. * @param {function(value: T, index: number) => Observable} project A function
  36. * that, when applied to an item emitted by the source or the output Observable,
  37. * returns an Observable.
  38. * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
  39. * Observables being subscribed to concurrently.
  40. * @param {Scheduler} [scheduler=null] The IScheduler to use for subscribing to
  41. * each projected inner Observable.
  42. * @return {Observable} An Observable that emits the source values and also
  43. * result of applying the projection function to each value emitted on the
  44. * output Observable and and merging the results of the Observables obtained
  45. * from this transformation.
  46. * @method expand
  47. * @owner Observable
  48. */
  49. export function expand(project, concurrent, scheduler) {
  50. if (concurrent === void 0) {
  51. concurrent = Number.POSITIVE_INFINITY;
  52. }
  53. if (scheduler === void 0) {
  54. scheduler = undefined;
  55. }
  56. concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
  57. return higherOrder(project, concurrent, scheduler)(this);
  58. }
  59. //# sourceMappingURL=expand.js.map