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

Commit fe2a028

Browse files
docs(operators): add documentation for takeWhile
Close #103
1 parent 3535dce commit fe2a028

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed
+62-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,66 @@
11
import { OperatorDoc } from '../operator.model';
22

33
export const takeWhile: OperatorDoc = {
4-
'name': 'takeWhile',
5-
'operatorType': 'filtering'
4+
name: 'takeWhile',
5+
operatorType: 'filtering',
6+
signature:
7+
'public takeWhile(predicate: function(value: T, index: number): boolean): Observable<T>',
8+
parameters: [
9+
{
10+
name: 'predicate',
11+
type: 'function(value: T, index: number): boolean',
12+
attribute: '',
13+
description: `
14+
A function that evaluates a value emitted by the source Observable and returns a boolean.
15+
Also takes the (zero-based) index as the second argument.
16+
`
17+
}
18+
],
19+
marbleUrl: 'http://reactivex.io/rxjs/img/takeWhile.png',
20+
shortDescription: {
21+
description: `
22+
Emits values emitted by the source Observable so long as each value satisfies the given predicate,
23+
and then completes as soon as this predicate is not satisfied.
24+
`,
25+
extras: [
26+
{
27+
type: 'Tip',
28+
text: `
29+
Takes values from the source only while they pass the condition given. When the first value does not satisfy, it completes.
30+
`
31+
}
32+
]
33+
},
34+
walkthrough: {
35+
description: `
36+
<p>
37+
<span class="markdown-code">takeWhile</span> subscribes and begins mirroring the source Observable.
38+
</p>
39+
<p>
40+
Each value emitted on the source is given to the predicate function which returns a boolean,
41+
representing a condition to be satisfied by the source values.
42+
</p>
43+
<p>
44+
The output Observable emits the source values until such time as the predicate returns false,
45+
at which point <span class="takeWhile"> stops mirroring the source Observable and completes the output Observable.
46+
</p>
47+
`
48+
},
49+
examples: [
50+
{
51+
name: `
52+
Emit click events only while the clientX property is greater than 100
53+
`,
54+
code: `
55+
const clicks = Rx.Observable.fromEvent(document, 'click');
56+
const result = clicks.takeWhile(ev => ev.clientX > 100);
57+
result.subscribe(x => console.log(x));
58+
`,
59+
externalLink: {
60+
platform: 'JSBin',
61+
url: 'http://jsbin.com/lasosinudi/embed?js,console,output'
62+
}
63+
}
64+
],
65+
relatedOperators: ['take', 'takeLast', 'takeUntil', 'skip']
666
};

0 commit comments

Comments
 (0)