This repository was archived by the owner on Oct 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathempty.ts
88 lines (84 loc) · 2.83 KB
/
empty.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { OperatorDoc } from '../operator.model';
export const empty: OperatorDoc = {
name: 'empty',
operatorType: 'creation',
returnValue: 'Observable',
signature: 'public empty(scheduler?: IScheduler): Observable',
parameters: [
{
name: 'scheduler',
type: 'IScheduler',
attribute: 'optional',
description:
'Allows scheduling the emission of the complete notification.'
}
],
marbleUrl: 'http://reactivex.io/rxjs/img/empty.png',
shortDescription: {
description:
'Creates an Observable that emits no items to the Observer' +
' and immediately emits a complete notification.'
},
walkthrough: {
description: `This static operator is useful for creating a simple
Observable that only emits the complete notification. It can be used for
composing with other Observables`
},
examples: [
{
name: 'Observable completes immediately',
code: `
import { empty } from 'rxjs/observable/empty';
const observable = empty();
const subscription = observable.subscribe({
next: () => console.log('next'), // does not log anything
complete: () => console.log('complete'), // logs 'complete'
});
`,
externalLink: {
platform: 'JSBin',
url: 'http://jsbin.com/hojacunecu/1/embed?js,console,output'
}
},
{
name: 'Observable emits initial value then completes',
code: `
import { startWith } from 'rxjs/operators';
import { empty } from 'rxjs/observable/empty';
const observable = empty().pipe(startWith('initial value'));
const subscription = observable.subscribe({
next: (val) => console.log(\`next: \${val}\`), // logs 'next: initial value'
complete: () => console.log('complete'), // logs 'complete'
});
`,
externalLink: {
platform: 'JSBin',
url: 'http://jsbin.com/tubonoradi/1/embed?js,console,output'
}
},
{
name: `Map and flatten only odd numbers to the sequence 'ax', 'bx', 'cx'`,
code: `
import { mergeMap } from 'rxjs/operators';
import { of } from 'rxjs/observable/of';
import { empty } from 'rxjs/observable/empty';
const source = of(1, 2, 3, 4, 5, 6, 7, 8, 9);
const result = source.pipe(
mergeMap(
x => x % 2 === 1 ? of(\`a\${x}\`, \`b\${x}\`, \`c\${x}\`) :
empty()
)
);
const subscription = result.subscribe({
next: (x) => console.log(x), // logs result values
complete: () => console.log('complete'), // logs 'complete'
});
`,
externalLink: {
platform: 'JSBin',
url: 'http://jsbin.com/qazabojiri/embed?js,console,output'
}
}
],
relatedOperators: ['create', 'of', 'throw']
};