|
1 | 1 | import { OperatorDoc } from '../operator.model'; |
2 | 2 |
|
3 | 3 | export const bufferTime: OperatorDoc = { |
4 | | - 'name': 'bufferTime', |
5 | | - 'operatorType': 'transformation' |
| 4 | + name: 'bufferTime', |
| 5 | + operatorType: 'transformation', |
| 6 | + signature: `bufferTime( |
| 7 | + bufferTimeSpan: number, |
| 8 | + bufferCreationInterval: number, |
| 9 | + maxBufferSize: number, |
| 10 | + scheduler: Scheduler): Observable<T[]>`, |
| 11 | + parameters: [ |
| 12 | + { |
| 13 | + name: 'bufferTimeSpan', |
| 14 | + type: 'number', |
| 15 | + attribute: '', |
| 16 | + description: `The amount of time (in milliseconds) to fill each buffer array.` |
| 17 | + }, |
| 18 | + { |
| 19 | + name: 'bufferCreationInterval', |
| 20 | + type: 'number', |
| 21 | + attribute: 'optional', |
| 22 | + description: `The interval (in milliseconds) at which to start new buffers.` |
| 23 | + }, |
| 24 | + { |
| 25 | + name: 'maxBufferSize', |
| 26 | + type: 'number', |
| 27 | + attribute: 'optional', |
| 28 | + description: `The maximum amount of items per buffer.` |
| 29 | + }, |
| 30 | + { |
| 31 | + name: 'scheduler', |
| 32 | + type: 'Scheduler', |
| 33 | + attribute: `optional |
| 34 | + default: async`, |
| 35 | + description: `The scheduler on which to schedule the intervals that determine buffer boundaries.` |
| 36 | + } |
| 37 | + ], |
| 38 | + marbleUrl: 'http://reactivex.io/rxjs/img/bufferTime.png', |
| 39 | + shortDescription: { |
| 40 | + description: `Buffers the source Observable values for a specific time period. |
| 41 | +
|
| 42 | + <span class="informal">Collects values from the past as an array, and emits those arrays periodically in time.</span>` |
| 43 | + }, |
| 44 | + walkthrough: { |
| 45 | + description: ` |
| 46 | + Buffers values from the source for a specific time duration <code>bufferTimeSpan</code>. |
| 47 | + It emits and resets the buffer every <code>bufferTimeSpan</code> milliseconds, |
| 48 | + unless the optional argument <code>bufferCreationInterval</code> is given. |
| 49 | + If <code>bufferCreationInterval</code> is given, |
| 50 | + this operator emits the buffered values and re-opens the buffer every <code>bufferCreationInterval</code> milliseconds |
| 51 | + and closes (no further values are buffered) the buffer every <code>bufferTimeSpan</code> milliseconds. |
| 52 | + When the optional argument <code>maxBufferSize</code> is specified, |
| 53 | + the buffer will be closed either after <code>bufferTimeSpan</code> milliseconds |
| 54 | + or when it contains <code>maxBufferSize</code> elements.` |
| 55 | + }, |
| 56 | + examples: [ |
| 57 | + { |
| 58 | + name: |
| 59 | + 'After every two and a half seconds, emit an array of the click events during that timeframe', |
| 60 | + code: ` |
| 61 | +import { fromEvent } from 'rxjs/observable/fromEvent'; |
| 62 | +import { map, bufferTime } from 'rxjs/operators'; |
| 63 | +
|
| 64 | +const clicks = fromEvent(document, 'click'); |
| 65 | +const buffered = clicks.pipe( |
| 66 | + bufferTime(2500) |
| 67 | +); |
| 68 | +buffered.subscribe(x => console.log(x)); |
| 69 | + `, |
| 70 | + externalLink: { |
| 71 | + platform: 'JSBin', |
| 72 | + url: 'http://jsbin.com/fuqewiy/1/embed?js,console,output' |
| 73 | + } |
| 74 | + }, |
| 75 | + { |
| 76 | + name: |
| 77 | + 'Every five seconds, emit the click events from the next two seconds', |
| 78 | + code: ` |
| 79 | + import { fromEvent } from 'rxjs/observable/fromEvent'; |
| 80 | + import { map, bufferTime } from 'rxjs/operators'; |
| 81 | +
|
| 82 | + const clicks = fromEvent(document, 'click'); |
| 83 | + const buffered = clicks.pipe( |
| 84 | + bufferTime(2000, 5000) |
| 85 | + ); |
| 86 | + buffered.subscribe(x => console.log(x)); |
| 87 | +`, |
| 88 | + externalLink: { |
| 89 | + platform: 'JSBin', |
| 90 | + url: 'http://jsbin.com/xohupot/embed?js,console,output' |
| 91 | + } |
| 92 | + } |
| 93 | + ], |
| 94 | + relatedOperators: [ |
| 95 | + 'buffer', |
| 96 | + 'bufferCount', |
| 97 | + 'bufferToggle', |
| 98 | + 'bufferWhen', |
| 99 | + 'windowTime' |
| 100 | + ] |
6 | 101 | }; |
0 commit comments