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

Commit f65c556

Browse files
Merge pull request #176 from btroncone/distinctUntilChanged-doc
docs(operators): add documentation for distinctUntilChanged
2 parents d1b1ad5 + 9716b54 commit f65c556

File tree

1 file changed

+85
-2
lines changed

1 file changed

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

3+
// ported from:
4+
// http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-distinctUntilChanged
5+
36
export const distinctUntilChanged: OperatorDoc = {
4-
'name': 'distinctUntilChanged',
5-
'operatorType': 'filtering'
7+
name: 'distinctUntilChanged',
8+
operatorType: 'filtering',
9+
signature: 'public distinctUntilChanged(compare: function): Observable',
10+
useInteractiveMarbles: true,
11+
parameters: [
12+
{
13+
name: 'compare',
14+
type: 'function',
15+
attribute: 'optional',
16+
description:
17+
'Optional comparison function called to test if an item is distinct from the previous item in the source.'
18+
}
19+
],
20+
marbleUrl: 'http://reactivex.io/rxjs/img/distinctUntilChanged.png',
21+
shortDescription: {
22+
description: `
23+
Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from the previous item.
24+
`,
25+
extras: [
26+
{
27+
type: 'Tip',
28+
text: `
29+
<span class="markdown-code">distinctUntilChanged</span> uses
30+
<a
31+
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness"
32+
target="_blank"
33+
class="markdown-code">
34+
===
35+
</a> comparison by default.
36+
`
37+
}
38+
]
39+
},
40+
walkthrough: {
41+
description: `
42+
<p>
43+
This operator will compare each emitted item from the source to the previously emitted item,
44+
emitting only distinct values by comparison such that:
45+
</p>
46+
<ul>
47+
<li>
48+
If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted.
49+
</li>
50+
<li>
51+
If a comparator function is not provided, an equality check is used by default.
52+
</li>
53+
</ul>
54+
`
55+
},
56+
examples: [
57+
{
58+
name: 'A simple example with numbers',
59+
code: `
60+
Rx.Observable.of(1, 1, 2, 2, 2, 1, 1, 2, 3, 3, 4)
61+
.distinctUntilChanged()
62+
.subscribe(x => console.log(x));
63+
`,
64+
externalLink: {
65+
platform: 'JSBin',
66+
url: 'http://jsbin.com/poxayavuge/embed?js,console'
67+
}
68+
},
69+
{
70+
name: 'An example using a compare function',
71+
code: `
72+
Rx.Observable.of(
73+
{ age: 4, name: 'Foo'},
74+
{ age: 7, name: 'Bar'},
75+
{ age: 5, name: 'Foo'},
76+
{ age: 6, name: 'Foo'}
77+
)
78+
.distinctUntilChanged((p, q) => p.name === q.name)
79+
.subscribe(x => console.log(x));
80+
`,
81+
externalLink: {
82+
platform: 'JSBin',
83+
url: 'http://jsbin.com/duhexuhoxo/embed?js,console'
84+
}
85+
}
86+
],
87+
relatedOperators: [],
88+
additionalResources: []
689
};

0 commit comments

Comments
 (0)