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

Commit e981dda

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

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed
+59-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,63 @@
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+
},
26+
walkthrough: {
27+
description: `
28+
<p>
29+
<span class="markdown-code">takeWhile</span> subscribes and begins mirroring the source Observable.
30+
</p>
31+
<p>
32+
Each value emitted on the source is given to the predicate function which returns a boolean,
33+
representing a condition to be satisfied by the source values.
34+
</p>
35+
<p>
36+
The output Observable emits the source values until such time as the predicate returns false,
37+
at which point <span class="takeWhile"> stops mirroring the source Observable and completes the output Observable.
38+
</p>
39+
`
40+
},
41+
examples: [
42+
{
43+
name: `
44+
Emit click events only while the clientX property is greater than 100
45+
`,
46+
code: `
47+
import { fromEvent } from 'rxjs/observable/fromEvent';
48+
import { takeWhile } from 'rxjs/operators';
49+
50+
const clicks = fromEvent(document, 'click');
51+
const result = clicks.pipe(
52+
takeWhile(ev => ev.clientX > 100)
53+
);
54+
result.subscribe(x => console.log(x));
55+
`,
56+
externalLink: {
57+
platform: 'JSBin',
58+
url: 'http://jsbin.com/lasosinudi/embed?js,console,output'
59+
}
60+
}
61+
],
62+
relatedOperators: ['take', 'takeLast', 'takeUntil', 'skip']
663
};

0 commit comments

Comments
 (0)