|
1 | 1 | import { OperatorDoc } from '../operator.model';
|
2 | 2 |
|
3 | 3 | export const bufferCount: OperatorDoc = {
|
4 |
| - 'name': 'bufferCount', |
5 |
| - 'operatorType': 'transformation' |
| 4 | + name: 'bufferCount', |
| 5 | + operatorType: 'transformation', |
| 6 | + signature: ` bufferCount(bufferSize: number, startBufferEvery: number): Observable<T[]>`, |
| 7 | + parameters: [ |
| 8 | + { |
| 9 | + name: 'bufferSize', |
| 10 | + type: 'number', |
| 11 | + attribute: '', |
| 12 | + description: `The maximum size of the buffer emitted.` |
| 13 | + }, |
| 14 | + { |
| 15 | + name: 'startBufferEvery', |
| 16 | + type: 'number', |
| 17 | + attribute: 'optional', |
| 18 | + description: `Interval at which to start a new buffer. For example if startBufferEvery is 2, |
| 19 | + then a new buffer will be started on every other value from the source. |
| 20 | + A new buffer is started at the beginning of the source by default.` |
| 21 | + } |
| 22 | + ], |
| 23 | + marbleUrl: 'http://reactivex.io/rxjs/img/bufferCount.png', |
| 24 | + shortDescription: { |
| 25 | + description: ` |
| 26 | + Buffers the source Observable values until the size hits the maximum <span class="markdown-code">bufferSize</span> given. |
| 27 | + <span class="informal"> |
| 28 | + Collects values from the past as an array, |
| 29 | + and emits that array only when its size reaches <span class="markdown-code">bufferSize</span>. |
| 30 | + </span>` |
| 31 | + }, |
| 32 | + walkthrough: { |
| 33 | + description: ` |
| 34 | + Buffers a number of values from the source Observable |
| 35 | + by <span class="markdown-code">bufferSize</span> then emits the buffer and clears it, |
| 36 | + and starts a new buffer each <span class="markdown-code">startBufferEvery</span> values. |
| 37 | + If <span class="markdown-code">startBufferEvery</span> is not provided or is null, |
| 38 | + then new buffers are started immediately at the start of the source and when each buffer closes and is emitted. |
| 39 | + ` |
| 40 | + }, |
| 41 | + examples: [ |
| 42 | + { |
| 43 | + name: 'Every two clicks, emit those two click events as an array', |
| 44 | + code: ` |
| 45 | + import { fromEvent } from 'rxjs/observable/fromEvent'; |
| 46 | + import { map, bufferCount } from 'rxjs/operators'; |
| 47 | +
|
| 48 | + const clicks$ = fromEvent(document, 'click'); |
| 49 | + const buffered$ = clicks$.pipe( |
| 50 | + map(e => {return {X: e.clientX, Y: e.clientY};}), |
| 51 | + bufferCount(2) |
| 52 | + ); |
| 53 | + buffered$.subscribe(x => console.log(x)); |
| 54 | + `, |
| 55 | + externalLink: { |
| 56 | + platform: 'JSBin', |
| 57 | + url: 'http://jsbin.com/ceripaf/1/embed?js,console,output' |
| 58 | + } |
| 59 | + }, |
| 60 | + { |
| 61 | + name: 'On every click, emit the last two click events as an array', |
| 62 | + code: ` |
| 63 | + import { fromEvent } from 'rxjs/observable/fromEvent'; |
| 64 | + import { map, bufferCount } from 'rxjs/operators'; |
| 65 | +
|
| 66 | + const clicks$ = fromEvent(document, 'click'); |
| 67 | + const buffered$ = clicks$.pipe( |
| 68 | + map(e => {return {X: e.clientX, Y: e.clientY};}), |
| 69 | + bufferCount(2, 1) |
| 70 | + ); |
| 71 | + buffered$.subscribe(x => console.log(x)); |
| 72 | +`, |
| 73 | + externalLink: { |
| 74 | + platform: 'JSBin', |
| 75 | + url: 'http://jsbin.com/cenuwip/1/embed?js,console,output' |
| 76 | + } |
| 77 | + } |
| 78 | + ], |
| 79 | + relatedOperators: [ |
| 80 | + 'buffer', |
| 81 | + 'bufferTime', |
| 82 | + 'bufferToggle', |
| 83 | + 'bufferWhen', |
| 84 | + 'pairwise', |
| 85 | + 'windowCount' |
| 86 | + ] |
6 | 87 | };
|
0 commit comments