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

Commit 47585b1

Browse files
Merge branch 'master' into docs-withLatestFrom
2 parents 142d87a + f77497f commit 47585b1

File tree

5 files changed

+297
-10
lines changed

5 files changed

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

33
export const concat: OperatorDoc = {
4-
'name': 'concat',
5-
'operatorType': 'combination'
4+
name: 'concat',
5+
operatorType: 'combination',
6+
signature:
7+
'public static concat(input1: ObservableInput, input2: ObservableInput, scheduler: Scheduler): Observable',
8+
parameters: [
9+
{
10+
name: 'input1',
11+
type: 'ObservableInput',
12+
attribute: '',
13+
description: 'An input Observable to concatenate with others.'
14+
},
15+
{
16+
name: 'input2',
17+
type: 'ObservableInput',
18+
attribute: '',
19+
description:
20+
'An input Observable to concatenate with others. More than one input Observables may be given as argument.'
21+
},
22+
{
23+
name: 'scheduler',
24+
type: 'Scheduler',
25+
attribute: 'optional default: null',
26+
description:
27+
'An optional IScheduler to schedule each Observable subscription on.'
28+
}
29+
],
30+
marbleUrl: 'http://reactivex.io/rxjs/img/concat.png',
31+
shortDescription: {
32+
description:
33+
'Creates an output Observable which sequentially emits all values from given Observable and then moves on to the next.',
34+
extras: [
35+
{
36+
type: 'Tip',
37+
text:
38+
'Concatenates multiple Observables together by sequentially emitting their values, one Observable after the other.'
39+
}
40+
]
41+
},
42+
walkthrough: {
43+
description: `
44+
<p><span class='markdown-code'>concat</span> joins multiple Observables together, by subscribing to them one at a time and
45+
merging their results into the output Observable. You can pass either an array of
46+
Observables, or put them directly as arguments. Passing an empty array will result
47+
in Observable that completes immediately.</p>
48+
49+
<p><span class='markdown-code'>concat</span> will subscribe to first input Observable and emit all its values, without
50+
changing or affecting them in any way. When that Observable completes, it will
51+
subscribe to then next Observable passed and, again, emit its values. This will be
52+
repeated, until the operator runs out of Observables. When last input Observable completes,
53+
<span class='markdown-code'>concat</span> will complete as well. At any given moment only one Observable passed to operator
54+
emits values. If you would like to emit values from passed Observables concurrently, check out
55+
<a href='/#/operators/merge' class='markdown-code'>merge</a> instead, especially with optional
56+
<span class='markdown-code'>concurrent</span> parameter.
57+
As a matter of fact, <span class='markdown-code'>concat</span> is an equivalent of
58+
<a href='/#/operators/merge' class='markdown-code'>merge</a> operator with
59+
<span class='markdown-code'>concurrent</span> parameter set to <span class='markdown-code'>1</span>.</p>
60+
61+
<p>Note that if some input Observable never completes, <span class='markdown-code'>concat</span> will also never complete
62+
and Observables following the one that did not complete will never be subscribed. On the other
63+
hand, if some Observable simply completes immediately after it is subscribed, it will be
64+
invisible for <span class='markdown-code'>concat</span>, which will just move on to the next Observable.</p>
65+
66+
<p>If any Observable in chain errors, instead of passing control to the next Observable,
67+
<span class='markdown-code'>concat</span> will error immediately as well. Observables that would be subscribed after
68+
the one that emitted error, never will.</p>
69+
70+
<p>If you pass to <span class='markdown-code'>concat</span> the same Observable many times, its stream of values
71+
will be 'replayed' on every subscription, which means you can repeat given Observable
72+
as many times as you like. If passing the same Observable to <span class='markdown-code'>concat</span> 1000 times becomes tedious,
73+
you can always use <span class='markdown-code'>repeat</span>.</p>
74+
`
75+
},
76+
examples: [
77+
{
78+
name:
79+
'Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10',
80+
code: `
81+
const timer = Rx.Observable.interval(1000).take(4);
82+
const sequence = Rx.Observable.range(1, 10);
83+
const result = Rx.Observable.concat(timer, sequence);
84+
result.subscribe(x => console.log(x));
85+
86+
// results in:
87+
// 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 -immediate-> 1 ... 10
88+
`,
89+
externalLink: {
90+
platform: 'JSBin',
91+
url: 'http://jsbin.com/doqoyimaxu/embed?js,console'
92+
}
93+
},
94+
{
95+
name: 'Concatenate an array of 3 Observables',
96+
code: `
97+
const timer1 = Rx.Observable.interval(1000).take(10);
98+
const timer2 = Rx.Observable.interval(2000).take(6);
99+
const timer3 = Rx.Observable.interval(500).take(10);
100+
const result = timer1.concat(timer2, timer3);
101+
result.subscribe(x => console.log(x));
102+
103+
// results in the following:
104+
// (Prints to console sequentially)
105+
// -1000ms-> 0 -1000ms-> 1 -1000ms-> ... 9
106+
// -2000ms-> 0 -2000ms-> 1 -2000ms-> ... 5
107+
// -500ms-> 0 -500ms-> 1 -500ms-> ... 9
108+
`,
109+
externalLink: {
110+
platform: 'JSBin',
111+
url: 'http://jsbin.com/decaromone/1/embed?js,console'
112+
}
113+
}
114+
],
115+
relatedOperators: ['concatAll', 'concatMap', 'concatMapTo']
6116
};
Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
import { OperatorDoc } from '../operator.model';
22

33
export const startWith: OperatorDoc = {
4-
'name': 'startWith',
5-
'operatorType': 'combination'
4+
name: 'startWith',
5+
operatorType: 'combination',
6+
marbleUrl: 'http://reactivex.io/rxjs/img/startWith.png',
7+
signature: 'public startWith(values: ...T, scheduler: Scheduler): Observable',
8+
shortDescription: {
9+
description:
10+
'Returns an Observable that emits the items you specify as arguments before it begins to emit items emitted by the source Observable.'
11+
},
12+
parameters: [
13+
{
14+
name: 'values',
15+
type: '...T',
16+
attribute: '',
17+
description: 'Items you want the modified Observable to emit first.'
18+
},
19+
{
20+
name: 'scheduler',
21+
type: 'Scheduler',
22+
attribute: 'optional',
23+
description:
24+
'A IScheduler to use for scheduling the emissions of the next notifications.'
25+
}
26+
]
627
};
Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,79 @@
11
import { OperatorDoc } from '../operator.model';
22

33
export const filter: OperatorDoc = {
4-
'name': 'filter',
5-
'operatorType': 'filtering'
4+
name: 'filter',
5+
operatorType: 'filtering',
6+
signature:
7+
'public filter(predicate: function(value: T, index: number): boolean, thisArg: any): Observable',
8+
parameters: [
9+
{
10+
name: 'predicate',
11+
type: 'function(value: T, index: number): boolean',
12+
attribute: '',
13+
description: `A function that evaluates each value emitted by the source Observable.
14+
If it returns true, the value is emitted, if false the value is not passed to the output Observable.
15+
The index parameter is the number i for the i-th source emission that has happened since the subscription,
16+
starting from the number 0.`
17+
},
18+
{
19+
name: 'thisArg',
20+
type: 'any',
21+
attribute: 'optional',
22+
description:
23+
'An optional argument to determine the value of this in the predicate function.'
24+
}
25+
],
26+
marbleUrl: 'http://reactivex.io/rxjs/img/filter.png',
27+
shortDescription: {
28+
description:
29+
'Filter items emitted by the source Observable by only emitting those that satisfy a specified predicate.',
30+
extras: [
31+
{
32+
type: 'Tip',
33+
text: `
34+
Like
35+
<a
36+
target="_blank"
37+
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter">
38+
Array.prototype.filter()
39+
</a>,
40+
it only emits a value from the source if it passes a criterion function.
41+
`
42+
}
43+
]
44+
},
45+
walkthrough: {
46+
description: `
47+
<p>
48+
Similar to the well-known <span class="markdown-code">Array.prototype.filter</span>
49+
method, this operator takes values from the source Observable,
50+
passes them through a predicate function and only emits those values that yielded true.
51+
</p>
52+
`
53+
},
54+
examples: [
55+
{
56+
name: 'Filter for even numbers',
57+
code: `
58+
//emit (1,2,3,4,5)
59+
const source = Rx.Observable.from([1, 2, 3, 4, 5]);
60+
//filter out non-even numbers
61+
const example = source.filter(num => num % 2 === 0);
62+
//output: "Even number: 2", "Even number: 4"
63+
const subscribe = example.subscribe(val => console.log('Even number: ' + val));
64+
`,
65+
externalLink: {
66+
platform: 'JSBin',
67+
url: 'http://jsbin.com/vafogoluye/1/embed?js,console'
68+
}
69+
}
70+
],
71+
relatedOperators: [
72+
'distinct',
73+
'distinctUntilChanged',
74+
'distinctUntilKeyChanged',
75+
'ignoreElements',
76+
'partition',
77+
'skip'
78+
]
679
};
Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
import { OperatorDoc } from '../operator.model';
22

33
export const skip: OperatorDoc = {
4-
'name': 'skip',
5-
'operatorType': 'filtering'
4+
name: 'skip',
5+
operatorType: 'filtering',
6+
signature: 'public skip(count: Number): Observable',
7+
parameters: [
8+
{
9+
name: 'count',
10+
type: 'Number',
11+
attribute: '',
12+
description:
13+
'Returns an Observable that skips the first count items emitted by the source Observable.'
14+
}
15+
],
16+
marbleUrl: 'http://reactivex.io/rxjs/img/skip.png',
17+
shortDescription: {
18+
description:
19+
'Returns an Observable that skips the first count items emitted by the source Observable.'
20+
},
21+
examples: [
22+
{
23+
name: 'Skipping values before emission',
24+
code: `
25+
//emit every 1s
26+
const source = Rx.Observable.interval(1000);
27+
//skip the first 5 emitted values
28+
const example = source.skip(5);
29+
//output: 5...6...7...8........
30+
const subscribe = example.subscribe(val => console.log(val));
31+
`,
32+
externalLink: {
33+
platform: 'JSBin',
34+
url: 'http://jsbin.com/hacepudabi/1/embed?js,console'
35+
}
36+
}
37+
]
638
};
Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,57 @@
11
import { OperatorDoc } from '../operator.model';
22

33
export const take: OperatorDoc = {
4-
'name': 'take',
5-
'operatorType': 'filtering'
4+
name: 'take',
5+
operatorType: 'filtering',
6+
signature: 'public take(count: number): Observable<T>',
7+
useInteractiveMarbles: true,
8+
parameters: [
9+
{
10+
name: 'count',
11+
type: 'number',
12+
attribute: '',
13+
description: 'The maximum number of next values to emit.'
14+
}
15+
],
16+
marbleUrl: 'http://reactivex.io/rxjs/img/take.png',
17+
shortDescription: {
18+
description: `Emits only the first count values emitted by the source Observable.`,
19+
extras: [
20+
{
21+
type: 'Tip',
22+
text: `Takes the first count values from the source, then completes.`
23+
}
24+
]
25+
},
26+
walkthrough: {
27+
description: `<p>
28+
<span class="markdown-code">take</span> returns an Observable that emits only the first count values emitted by the source Observable.
29+
</p>
30+
<p>
31+
If the source emits fewer than count values then all of its values are emitted.
32+
After that, it completes, regardless if the source completes.
33+
</p>`
34+
},
35+
examples: [
36+
{
37+
name:
38+
'Take the first 5 seconds of an infinite 1-second interval Observable',
39+
code: `
40+
const interval = Rx.Observable.interval(1000);
41+
const five = interval.take(5);
42+
five.subscribe(x => console.log(x));
43+
// Logs below values
44+
// 0
45+
// 1
46+
// 2
47+
// 3
48+
// 4
49+
`,
50+
externalLink: {
51+
platform: 'JSBin',
52+
url: 'http://jsbin.com/yujema/embed?html,js,console'
53+
}
54+
}
55+
],
56+
relatedOperators: ['takeLast', 'takeUntil', 'takeWhile', 'skip']
657
};

0 commit comments

Comments
 (0)