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 pathdefaultIfEmpty.ts
67 lines (63 loc) · 2 KB
/
defaultIfEmpty.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
import { OperatorDoc } from '../operator.model';
export const defaultIfEmpty: OperatorDoc = {
name: 'defaultIfEmpty',
operatorType: 'conditional',
signature: 'public defaultIfEmpty(defaultValue: any): Observable',
marbleUrl: 'http://reactivex.io/rxjs/img/defaultIfEmpty.png',
parameters: [
{
name: 'defaultValue',
type: 'any',
attribute: 'optional default: null',
description: 'The default value used if the source Observable is empty.'
}
],
shortDescription: {
description: `Emits a given value if the source Observable completes without emitting any
<span class="markdown-code">next</span> value, otherwise mirrors the source Observable.
`,
extras: [
{
type: 'Tip',
text: `
If the source Observable turns out to be empty, then this operator will emit a default value.
`
}
]
},
walkthrough: {
description: `
<p>
<span class="markdown-code">defaultIfEmpty</span> emits the values emitted by the source
Observable or a specified default value if the source Observable is empty (completes
without having emitted any <span class="markdown-code">next</span> value).
</p>
`
},
examples: [
{
name: `If no clicks happen in 3 seconds, then emit 'no clicks'`,
code: `
import { fromEvent } from 'rxjs/observable/fromEvent';
import { interval } from 'rxjs/observable/interval';
import { defaultIfEmpty, takeUntil } from 'rxjs/operators';
const clicks = fromEvent(document, 'click');
const result = clicks.pipe(
takeUntil(interval(3000)),
defaultIfEmpty('no clicks')
);
result.subscribe(x => console.log(x));
/*
Example console output
no clicks
*/
`,
externalLink: {
platform: 'JSBin',
url: 'http://jsbin.com/verovam/embed?js,console,output'
}
}
],
relatedOperators: ['empty', 'last'],
additionalResources: []
};