40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
/** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */
|
|
import * as tslib_1 from "tslib";
|
|
import { Subscriber } from '../Subscriber';
|
|
export function defaultIfEmpty(defaultValue) {
|
|
if (defaultValue === void 0) {
|
|
defaultValue = null;
|
|
}
|
|
return function (source) { return source.lift(new DefaultIfEmptyOperator(defaultValue)); };
|
|
}
|
|
var DefaultIfEmptyOperator = /*@__PURE__*/ (function () {
|
|
function DefaultIfEmptyOperator(defaultValue) {
|
|
this.defaultValue = defaultValue;
|
|
}
|
|
DefaultIfEmptyOperator.prototype.call = function (subscriber, source) {
|
|
return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));
|
|
};
|
|
return DefaultIfEmptyOperator;
|
|
}());
|
|
var DefaultIfEmptySubscriber = /*@__PURE__*/ (function (_super) {
|
|
tslib_1.__extends(DefaultIfEmptySubscriber, _super);
|
|
function DefaultIfEmptySubscriber(destination, defaultValue) {
|
|
var _this = _super.call(this, destination) || this;
|
|
_this.defaultValue = defaultValue;
|
|
_this.isEmpty = true;
|
|
return _this;
|
|
}
|
|
DefaultIfEmptySubscriber.prototype._next = function (value) {
|
|
this.isEmpty = false;
|
|
this.destination.next(value);
|
|
};
|
|
DefaultIfEmptySubscriber.prototype._complete = function () {
|
|
if (this.isEmpty) {
|
|
this.destination.next(this.defaultValue);
|
|
}
|
|
this.destination.complete();
|
|
};
|
|
return DefaultIfEmptySubscriber;
|
|
}(Subscriber));
|
|
//# sourceMappingURL=defaultIfEmpty.js.map
|