Front end of the Slack clone application.

expand.js 2.4KB

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