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

Commit 3535dce

Browse files
Merge pull request #196 from ashwin-sureshkumar/issue-92
docs(operators): add documentation for first
2 parents f38fac7 + da2c8bf commit 3535dce

File tree

1 file changed

+86
-2
lines changed

1 file changed

+86
-2
lines changed

src/operator-docs/filtering/first.ts

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

33
export const first: OperatorDoc = {
4-
'name': 'first',
5-
'operatorType': 'filtering'
4+
name: 'first',
5+
operatorType: 'filtering',
6+
signature: `public first(predicate: function(value: T, index: number, source: Observable<T>):
7+
boolean, resultSelector: function(value: T, index: number): R, defaultValue: R): Observable<T | R>`,
8+
parameters: [
9+
{
10+
name: 'predicate',
11+
type:
12+
'function(value: T, index: number, source: Observable<T>): boolean ',
13+
attribute: 'optional',
14+
description:
15+
'An optional function called with each item to test for condition matching.'
16+
},
17+
{
18+
name: 'resultSelector',
19+
type: 'function(value: T, index: number): R',
20+
attribute: 'optional',
21+
description: `
22+
A function to produce the value on the output Observable based on the
23+
values and the indices of the source Observable. The arguments passed to this function are:
24+
value: the value that was emitted on the source.
25+
index: the "index" of the value from the source.
26+
`
27+
},
28+
{
29+
name: 'defaultValue',
30+
type: 'R',
31+
attribute: 'optional',
32+
description:
33+
'The default value emitted in case no valid value was found on the source.'
34+
}
35+
],
36+
marbleUrl: 'http://reactivex.io/rxjs/img/first.png',
37+
shortDescription: {
38+
description: `Emits only the first value (or the first value that meets some condition) emitted by the source Observable.`,
39+
extras: [
40+
{
41+
type: 'Tip',
42+
text: `Emits only the first value. Or emits only the first value that passes some test.`
43+
}
44+
]
45+
},
46+
walkthrough: {
47+
description: `
48+
<p>
49+
If called with no arguments, first emits the first value of the source Observable, then completes.
50+
</p>
51+
<p>
52+
If called with a <span class="markdown-code">predicate</span> function,
53+
<span class="markdown-code>first</code> emits the first value of the source that matches the specified condition.
54+
</p>
55+
<p>
56+
It may also take a <span class="markdown-code">resultSelector</span> function to produce the output value from the input value,
57+
and a <span class="markdown-code">defaultValue</span> to emit in case the source completes before it is able to emit a valid value.
58+
</p>
59+
<p>
60+
Throws an error if defaultValue was not provided and a matching element is not found.
61+
</p>
62+
`
63+
},
64+
examples: [
65+
{
66+
name: 'Emit only the X postition of first click that happens on the DOM',
67+
code: `
68+
const clicks = Rx.Observable.fromEvent(document, 'click');
69+
const result = clicks.first();
70+
result.subscribe(x => console.log(x));
71+
`,
72+
externalLink: {
73+
platform: 'JSBin',
74+
url: 'http://jsbin.com/zixuweg/1/embed?html,js,console,output'
75+
}
76+
},
77+
{
78+
name: 'Emits only the X postition of first click that happens on a DIV',
79+
code: `
80+
const clicks = Rx.Observable.fromEvent(document, 'click');
81+
const result = clicks.first(ev => ev.target.tagName === 'DIV');
82+
result.subscribe(x => console.log(x));
83+
`,
84+
externalLink: {
85+
platform: 'JSBin',
86+
url: 'http://jsbin.com/yuwebew/1/embed?js,console,output'
87+
}
88+
}
89+
]
690
};

0 commit comments

Comments
 (0)