1 | "use strict";
|
---|
2 | var __extends = (this && this.__extends) || (function () {
|
---|
3 | var extendStatics = function (d, b) {
|
---|
4 | extendStatics = Object.setPrototypeOf ||
|
---|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
---|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
---|
7 | return extendStatics(d, b);
|
---|
8 | }
|
---|
9 | return function (d, b) {
|
---|
10 | extendStatics(d, b);
|
---|
11 | function __() { this.constructor = d; }
|
---|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
---|
13 | };
|
---|
14 | })();
|
---|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
16 | var EmptyError_1 = require("../util/EmptyError");
|
---|
17 | var Subscriber_1 = require("../Subscriber");
|
---|
18 | function throwIfEmpty(errorFactory) {
|
---|
19 | if (errorFactory === void 0) { errorFactory = defaultErrorFactory; }
|
---|
20 | return function (source) {
|
---|
21 | return source.lift(new ThrowIfEmptyOperator(errorFactory));
|
---|
22 | };
|
---|
23 | }
|
---|
24 | exports.throwIfEmpty = throwIfEmpty;
|
---|
25 | var ThrowIfEmptyOperator = (function () {
|
---|
26 | function ThrowIfEmptyOperator(errorFactory) {
|
---|
27 | this.errorFactory = errorFactory;
|
---|
28 | }
|
---|
29 | ThrowIfEmptyOperator.prototype.call = function (subscriber, source) {
|
---|
30 | return source.subscribe(new ThrowIfEmptySubscriber(subscriber, this.errorFactory));
|
---|
31 | };
|
---|
32 | return ThrowIfEmptyOperator;
|
---|
33 | }());
|
---|
34 | var ThrowIfEmptySubscriber = (function (_super) {
|
---|
35 | __extends(ThrowIfEmptySubscriber, _super);
|
---|
36 | function ThrowIfEmptySubscriber(destination, errorFactory) {
|
---|
37 | var _this = _super.call(this, destination) || this;
|
---|
38 | _this.errorFactory = errorFactory;
|
---|
39 | _this.hasValue = false;
|
---|
40 | return _this;
|
---|
41 | }
|
---|
42 | ThrowIfEmptySubscriber.prototype._next = function (value) {
|
---|
43 | this.hasValue = true;
|
---|
44 | this.destination.next(value);
|
---|
45 | };
|
---|
46 | ThrowIfEmptySubscriber.prototype._complete = function () {
|
---|
47 | if (!this.hasValue) {
|
---|
48 | var err = void 0;
|
---|
49 | try {
|
---|
50 | err = this.errorFactory();
|
---|
51 | }
|
---|
52 | catch (e) {
|
---|
53 | err = e;
|
---|
54 | }
|
---|
55 | this.destination.error(err);
|
---|
56 | }
|
---|
57 | else {
|
---|
58 | return this.destination.complete();
|
---|
59 | }
|
---|
60 | };
|
---|
61 | return ThrowIfEmptySubscriber;
|
---|
62 | }(Subscriber_1.Subscriber));
|
---|
63 | function defaultErrorFactory() {
|
---|
64 | return new EmptyError_1.EmptyError();
|
---|
65 | }
|
---|
66 | //# sourceMappingURL=throwIfEmpty.js.map |
---|