Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Commit 403d845

Browse files
committed
docs(operators): add documentation for pairwise
1 parent 4ce8d6f commit 403d845

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed
Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
11
import { OperatorDoc } from '../operator.model';
22

33
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']
651
};

0 commit comments

Comments
 (0)