Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
914 bytes
|
Line | |
---|
1 | import { Subscriber } from '../Subscriber';
|
---|
2 | export function defaultIfEmpty(defaultValue = null) {
|
---|
3 | return (source) => source.lift(new DefaultIfEmptyOperator(defaultValue));
|
---|
4 | }
|
---|
5 | class DefaultIfEmptyOperator {
|
---|
6 | constructor(defaultValue) {
|
---|
7 | this.defaultValue = defaultValue;
|
---|
8 | }
|
---|
9 | call(subscriber, source) {
|
---|
10 | return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));
|
---|
11 | }
|
---|
12 | }
|
---|
13 | class DefaultIfEmptySubscriber extends Subscriber {
|
---|
14 | constructor(destination, defaultValue) {
|
---|
15 | super(destination);
|
---|
16 | this.defaultValue = defaultValue;
|
---|
17 | this.isEmpty = true;
|
---|
18 | }
|
---|
19 | _next(value) {
|
---|
20 | this.isEmpty = false;
|
---|
21 | this.destination.next(value);
|
---|
22 | }
|
---|
23 | _complete() {
|
---|
24 | if (this.isEmpty) {
|
---|
25 | this.destination.next(this.defaultValue);
|
---|
26 | }
|
---|
27 | this.destination.complete();
|
---|
28 | }
|
---|
29 | }
|
---|
30 | //# sourceMappingURL=defaultIfEmpty.js.map |
---|
Note:
See
TracBrowser
for help on using the repository browser.