|
1 | 1 | import { OperatorDoc } from '../operator.model'; |
2 | 2 |
|
3 | 3 | export const pairwise: OperatorDoc = { |
4 | | - 'name': 'pairwise', |
5 | | - 'operatorType': 'combination' |
| 4 | + name: 'pairwise', |
| 5 | + operatorType: 'combination', |
| 6 | + marbleUrl: 'http://reactivex.io/rxjs/img/pairwise.png', |
| 7 | + signature: 'public pairwise(): Observable<Array<T>>', |
| 8 | + shortDescription: { |
| 9 | + description: |
| 10 | + 'Groups pairs of consecutive emissions together and emits them as an array of two values.', |
| 11 | + extras: [ |
| 12 | + { |
| 13 | + type: 'Tip', |
| 14 | + text: |
| 15 | + 'Puts the current value and previous value together as an array, and emits that.' |
| 16 | + } |
| 17 | + ] |
| 18 | + }, |
| 19 | + walkthrough: { |
| 20 | + description: ` |
| 21 | + <p>The Nth emission from the source Observable will cause the output Observable |
| 22 | + to emit an array [(N-1)th, Nth] of the previous and the current value, as a |
| 23 | + pair. For this reason, <code>pairwise</code> emits on the second and subsequent |
| 24 | + emissions from the source Observable, but not on the first emission, because |
| 25 | + there is no previous value in that case.</p> |
| 26 | + ` |
| 27 | + }, |
| 28 | + examples: [ |
| 29 | + { |
| 30 | + name: |
| 31 | + 'On every click (starting from the second), emit the relative distance to the previous click', |
| 32 | + code: ` |
| 33 | + const clicks = Rx.Observable.fromEvent(document, 'click'); |
| 34 | + const pairs = clicks.pairwise(); |
| 35 | + const distance = pairs.map(pair => { |
| 36 | + const x0 = pair[0].clientX; |
| 37 | + const y0 = pair[0].clientY; |
| 38 | + const x1 = pair[1].clientX; |
| 39 | + const y1 = pair[1].clientY; |
| 40 | + return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2)); |
| 41 | + }); |
| 42 | + distance.subscribe(x => console.log(x)); |
| 43 | + `, |
| 44 | + externalLink: { |
| 45 | + platform: 'JSBin', |
| 46 | + url: 'http://jsbin.com/wenazagegu/embed?js,console,output' |
| 47 | + } |
| 48 | + } |
| 49 | + ], |
| 50 | + relatedOperators: ['buffer', 'bufferCount'] |
6 | 51 | }; |
0 commit comments