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

Commit edd5da3

Browse files
committed
Merge branch 'master' into iss-121
2 parents 08284b6 + ec32c3a commit edd5da3

File tree

2 files changed

+152
-4
lines changed

2 files changed

+152
-4
lines changed

src/operator-docs/creation/from.ts

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

33
export const from: OperatorDoc = {
4-
'name': 'from',
5-
'operatorType': 'creation'
4+
name: 'from',
5+
operatorType: 'creation',
6+
signature: `from(ish: ArrayLike | ObservableInput, scheduler: Scheduler): Observable`,
7+
parameters: [
8+
{
9+
name: 'ish',
10+
type: 'ArrayLike | ObservableInput',
11+
attribute: '',
12+
description: `A subscribable object, a Promise, an Observable-like, an Array, an
13+
iterable or an array-like object to be converted.`
14+
},
15+
{
16+
name: 'scheduler',
17+
type: 'Scheduler',
18+
attribute: 'optional',
19+
description: `The scheduler on which to schedule the emissions of values.`
20+
}
21+
],
22+
marbleUrl: 'http://reactivex.io/rxjs/img/from.png',
23+
shortDescription: {
24+
description: `Creates an Observable from an Array, an array-like object, a Promise, an
25+
iterable object, or an Observable-like object.
26+
<span class="informal">Converts almost anything to an Observable.</span>`
27+
},
28+
walkthrough: {
29+
description: `Converts various other objects and data types into Observables. <span class="markdown-code">from</span>
30+
converts a Promise or an array-like or an
31+
<a href ='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable' target='_blank'>iterable</a>
32+
object into an Observable that emits the items in that promise or array or
33+
iterable. A String, in this context, is treated as an array of characters.
34+
Observable-like objects (contains a function named with the ES2015 Symbol
35+
for Observable) can also be converted through this operator.
36+
`
37+
},
38+
examples: [
39+
{
40+
name: 'Converts an array to an Observable',
41+
code: `
42+
const array = [10, 20, 30];
43+
const result = Rx.Observable.from(array);
44+
result.subscribe(x => console.log(x));
45+
46+
// Results in the following:
47+
// 10 20 30`,
48+
externalLink: {
49+
platform: 'JSBin',
50+
url: 'http://jsbin.com/qodocay/embed?js,console'
51+
}
52+
},
53+
{
54+
name: 'Convert an infinite iterable (from a generator) to an Observable',
55+
code: `
56+
function* generateDoubles(seed) {
57+
let i = seed;
58+
while (true) {
59+
yield i;
60+
i = 2 * i; // double it
61+
}
62+
}
63+
const iterator = generateDoubles(3);
64+
const result = Rx.Observable.from(iterator).take(10);
65+
result.subscribe(x => console.log(x));
66+
// Results in the following:
67+
// 3 6 12 24 48 96 192 384 768 1536`,
68+
externalLink: {
69+
platform: 'JSBin',
70+
url: 'http://jsbin.com/kidevan/embed?js,console'
71+
}
72+
},
73+
{
74+
name:
75+
'Using <span class="markdown-code">from</span> with async scheduler',
76+
code: `
77+
console.log('start');
78+
const array = [10, 20, 30];
79+
const result = Rx.Observable.from(array, Rx.Scheduler.async);
80+
result.subscribe(x => console.log(x));
81+
console.log('end');
82+
// Results in the following:
83+
// start end 10 20 30`,
84+
externalLink: {
85+
platform: 'JSBin',
86+
url: 'http://jsbin.com/xunesam/embed?js,console'
87+
}
88+
}
89+
],
90+
relatedOperators: ['create', 'fromEvent', 'fromEventPattern', 'fromPromise']
691
};
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)