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

Commit 6e48188

Browse files
committed
docs(operators): add documentation for distinctUntilChanged
1 parent c16f79b commit 6e48188

File tree

1 file changed

+91
-2
lines changed

1 file changed

+91
-2
lines changed
Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,95 @@
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+
// displays
63+
// 1, 2, 1, 2, 3, 4
64+
.subscribe(x => console.log(x));
65+
`,
66+
externalLink: {
67+
platform: 'JSBin',
68+
url: 'http://jsbin.com/begerivegu/1/embed?js,console'
69+
}
70+
},
71+
{
72+
name: 'An example using a compare function',
73+
code: `
74+
Rx.Observable.of(
75+
{ age: 4, name: 'Foo'},
76+
{ age: 7, name: 'Bar'},
77+
{ age: 5, name: 'Foo'},
78+
{ age: 6, name: 'Foo'}
79+
)
80+
.distinctUntilChanged((p, q) => p.name === q.name)
81+
// displays:
82+
// { age: 4, name: 'Foo' }
83+
// { age: 7, name: 'Bar' }
84+
// { age: 5, name: 'Foo' }
85+
.subscribe(x => console.log(x));
86+
`,
87+
externalLink: {
88+
platform: 'JSBin',
89+
url: 'http://jsbin.com/fibaxeriku/1/embed?js,console'
90+
}
91+
}
92+
],
93+
relatedOperators: [],
94+
additionalResources: []
695
};

0 commit comments

Comments
 (0)