Front end of the Slack clone application.

bufferCount.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { bufferCount as higherOrder } from '../operators/bufferCount';
  2. /**
  3. * Buffers the source Observable values until the size hits the maximum
  4. * `bufferSize` given.
  5. *
  6. * <span class="informal">Collects values from the past as an array, and emits
  7. * that array only when its size reaches `bufferSize`.</span>
  8. *
  9. * <img src="./img/bufferCount.png" width="100%">
  10. *
  11. * Buffers a number of values from the source Observable by `bufferSize` then
  12. * emits the buffer and clears it, and starts a new buffer each
  13. * `startBufferEvery` values. If `startBufferEvery` is not provided or is
  14. * `null`, then new buffers are started immediately at the start of the source
  15. * and when each buffer closes and is emitted.
  16. *
  17. * @example <caption>Emit the last two click events as an array</caption>
  18. * var clicks = Rx.Observable.fromEvent(document, 'click');
  19. * var buffered = clicks.bufferCount(2);
  20. * buffered.subscribe(x => console.log(x));
  21. *
  22. * @example <caption>On every click, emit the last two click events as an array</caption>
  23. * var clicks = Rx.Observable.fromEvent(document, 'click');
  24. * var buffered = clicks.bufferCount(2, 1);
  25. * buffered.subscribe(x => console.log(x));
  26. *
  27. * @see {@link buffer}
  28. * @see {@link bufferTime}
  29. * @see {@link bufferToggle}
  30. * @see {@link bufferWhen}
  31. * @see {@link pairwise}
  32. * @see {@link windowCount}
  33. *
  34. * @param {number} bufferSize The maximum size of the buffer emitted.
  35. * @param {number} [startBufferEvery] Interval at which to start a new buffer.
  36. * For example if `startBufferEvery` is `2`, then a new buffer will be started
  37. * on every other value from the source. A new buffer is started at the
  38. * beginning of the source by default.
  39. * @return {Observable<T[]>} An Observable of arrays of buffered values.
  40. * @method bufferCount
  41. * @owner Observable
  42. */
  43. export function bufferCount(bufferSize, startBufferEvery = null) {
  44. return higherOrder(bufferSize, startBufferEvery)(this);
  45. }
  46. //# sourceMappingURL=bufferCount.js.map