|
1 | 1 | import { OperatorDoc } from '../operator.model';
|
2 | 2 |
|
3 | 3 | export const windowOperator: OperatorDoc = {
|
4 |
| - 'name': 'window', |
5 |
| - 'operatorType': 'transformation' |
| 4 | + name: 'window', |
| 5 | + operatorType: 'transformation', |
| 6 | + signature: |
| 7 | + 'public window(windowBoundaries: Observable<any>): Observable<Observable<T>>', |
| 8 | + parameters: [ |
| 9 | + { |
| 10 | + name: 'windowBoundaries', |
| 11 | + type: 'Observable<any>', |
| 12 | + attribute: '', |
| 13 | + description: |
| 14 | + 'An Observable that completes the previous window and starts a new window.' |
| 15 | + } |
| 16 | + ], |
| 17 | + marbleUrl: 'http://reactivex.io/rxjs/img/window.png', |
| 18 | + shortDescription: { |
| 19 | + description: ` |
| 20 | + Branch out the source Observable values as a nested Observable |
| 21 | + whenever <span class="markdown-code">windowBoundaries</span> emits. |
| 22 | + `, |
| 23 | + extras: [ |
| 24 | + { |
| 25 | + type: 'Tip', |
| 26 | + text: ` |
| 27 | + It's like <a href="#/operators/buffer" class="markdown-code">buffer</a>, |
| 28 | + but emits a nested Observable instead of an array. |
| 29 | + ` |
| 30 | + } |
| 31 | + ] |
| 32 | + }, |
| 33 | + walkthrough: { |
| 34 | + description: ` |
| 35 | + <p> |
| 36 | + Returns an Observable that emits windows of items it collects |
| 37 | + from the source Observable. The output Observable emits connected, |
| 38 | + non-overlapping windows. It emits the current window and opens a new |
| 39 | + one whenever the Observable <span class="markdown-code">windowBoundaries</span> |
| 40 | + emits an item. Because each window is an Observable, the output is a higher-order Observable. |
| 41 | + </p> |
| 42 | + ` |
| 43 | + }, |
| 44 | + examples: [ |
| 45 | + { |
| 46 | + name: 'In every window of 1 second each, emit at most 2 click events', |
| 47 | + code: ` |
| 48 | + const clicks = Rx.Observable.fromEvent(document, 'click'); |
| 49 | + const interval = Rx.Observable.interval(1000); |
| 50 | + const result = clicks.window(interval) |
| 51 | + .map(win => win.take(2)) // each window has at most 2 emissions |
| 52 | + .mergeAll(); // flatten the Observable-of-Observables |
| 53 | + result.subscribe(x => console.log(x)); |
| 54 | + `, |
| 55 | + externalLink: { |
| 56 | + platform: 'JSBin', |
| 57 | + url: 'http://jsbin.com/racefub/embed?js,console,output' |
| 58 | + } |
| 59 | + } |
| 60 | + ], |
| 61 | + relatedOperators: [ |
| 62 | + 'windowCount', |
| 63 | + 'windowTime', |
| 64 | + 'windowToggle', |
| 65 | + 'windowWhen', |
| 66 | + 'buffer' |
| 67 | + ] |
6 | 68 | };
|
0 commit comments