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

Commit ffaac4f

Browse files
Merge pull request #174 from mustafamg/doc-switchmap
docs (Operator): add documentation for operator switchMap
2 parents 5059b48 + 60dac02 commit ffaac4f

File tree

1 file changed

+65
-2
lines changed

1 file changed

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

33
export const switchMap: OperatorDoc = {
4-
'name': 'switchMap',
5-
'operatorType': 'transformation'
4+
name: 'switchMap',
5+
operatorType: 'transformation',
6+
signature: `switchMap(project: (value: T, index: number) => ObservableInput<I>,
7+
resultSelector: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R): Observable`,
8+
parameters: [
9+
{
10+
name: 'project',
11+
type: 'function(value: T, index: number): ObservableInput',
12+
attribute: '',
13+
description: `A function that, when applied to an item emitted by the source
14+
Observable, returns an Observable.`
15+
},
16+
{
17+
name: 'resultSelector',
18+
type:
19+
'function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any',
20+
attribute: 'optional',
21+
description: `A function to produce the value on the output Observable based on the values
22+
and the indices of the source (outer) emission and the inner Observable
23+
emission. The arguments passed to this function are:
24+
- 'outerValue': the value that came from the source.
25+
- 'innerValue': the value that came from the projected Observable.
26+
- 'outerIndex': the "index" of the value that came from the source.
27+
- 'innerIndex': the "index" of the value from the projected Observable.`
28+
}
29+
],
30+
marbleUrl: 'http://reactivex.io/rxjs/img/switchMap.png',
31+
shortDescription: {
32+
description: `Projects each source value to an Observable which is merged in the output
33+
Observable, emitting values only from the most recently projected Observable.
34+
35+
<span class="informal">Maps each value to an Observable, then flattens all of
36+
these inner Observables using <code>switch</code>.</span>`
37+
},
38+
walkthrough: {
39+
description: `Returns an Observable that emits items based on applying a function that you
40+
supply to each item emitted by the source Observable, where that function
41+
returns an (so-called "inner") Observable. Each time it observes one of these
42+
inner Observables, the output Observable begins emitting the items emitted by
43+
that inner Observable. When a new inner Observable is emitted, <code>switchMap</code>
44+
stops emitting items from the earlier-emitted inner Observable and begins
45+
emitting items from the new one. It continues to behave like this for
46+
subsequent inner Observables.`
47+
},
48+
examples: [
49+
{
50+
name: 'Rerun an interval Observable on every click even',
51+
code: `
52+
const clicks = Rx.Observable.fromEvent(document, 'click');
53+
const result = clicks.switchMap((ev) => Rx.Observable.interval(1000));
54+
result.subscribe(x => console.log(x));
55+
`,
56+
externalLink: {
57+
platform: 'JSBin',
58+
url: 'http://jsbin.com/yehawof/edit?js,console,output'
59+
}
60+
}
61+
],
62+
relatedOperators: [
63+
'concatMap',
64+
'exhaustMap',
65+
'mergeMap',
66+
'switch',
67+
'switchMapTo'
68+
]
669
};

0 commit comments

Comments
 (0)