| 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; |
| 7 |
return extendStatics(d, b); |
| 8 |
}; |
| 9 |
return function (d, b) { |
| 10 |
if (typeof b !== "function" && b !== null) |
| 11 |
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); |
| 12 |
extendStatics(d, b); |
| 13 |
function __() { this.constructor = d; } |
| 14 |
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
| 15 |
}; |
| 16 |
})(); |
| 17 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 18 |
exports.ConnectableObservable = void 0; |
| 19 |
var Observable_1 = require("../Observable"); |
| 20 |
var Subscription_1 = require("../Subscription"); |
| 21 |
var refCount_1 = require("../operators/refCount"); |
| 22 |
var OperatorSubscriber_1 = require("../operators/OperatorSubscriber"); |
| 23 |
var lift_1 = require("../util/lift"); |
| 24 |
var ConnectableObservable = (function (_super) { |
| 25 |
__extends(ConnectableObservable, _super); |
| 26 |
function ConnectableObservable(source, subjectFactory) { |
| 27 |
var _this = _super.call(this) || this; |
| 28 |
_this.source = source; |
| 29 |
_this.subjectFactory = subjectFactory; |
| 30 |
_this._subject = null; |
| 31 |
_this._refCount = 0; |
| 32 |
_this._connection = null; |
| 33 |
if (lift_1.hasLift(source)) { |
| 34 |
_this.lift = source.lift; |
| 35 |
} |
| 36 |
return _this; |
| 37 |
} |
| 38 |
ConnectableObservable.prototype._subscribe = function (subscriber) { |
| 39 |
return this.getSubject().subscribe(subscriber); |
| 40 |
}; |
| 41 |
ConnectableObservable.prototype.getSubject = function () { |
| 42 |
var subject = this._subject; |
| 43 |
if (!subject || subject.isStopped) { |
| 44 |
this._subject = this.subjectFactory(); |
| 45 |
} |
| 46 |
return this._subject; |
| 47 |
}; |
| 48 |
ConnectableObservable.prototype._teardown = function () { |
| 49 |
this._refCount = 0; |
| 50 |
var _connection = this._connection; |
| 51 |
this._subject = this._connection = null; |
| 52 |
_connection === null || _connection === void 0 ? void 0 : _connection.unsubscribe(); |
| 53 |
}; |
| 54 |
ConnectableObservable.prototype.connect = function () { |
| 55 |
var _this = this; |
| 56 |
var connection = this._connection; |
| 57 |
if (!connection) { |
| 58 |
connection = this._connection = new Subscription_1.Subscription(); |
| 59 |
var subject_1 = this.getSubject(); |
| 60 |
connection.add(this.source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subject_1, undefined, function () { |
| 61 |
_this._teardown(); |
| 62 |
subject_1.complete(); |
| 63 |
}, function (err) { |
| 64 |
_this._teardown(); |
| 65 |
subject_1.error(err); |
| 66 |
}, function () { return _this._teardown(); }))); |
| 67 |
if (connection.closed) { |
| 68 |
this._connection = null; |
| 69 |
connection = Subscription_1.Subscription.EMPTY; |
| 70 |
} |
| 71 |
} |
| 72 |
return connection; |
| 73 |
}; |
| 74 |
ConnectableObservable.prototype.refCount = function () { |
| 75 |
return refCount_1.refCount()(this); |
| 76 |
}; |
| 77 |
return ConnectableObservable; |
| 78 |
}(Observable_1.Observable)); |
| 79 |
exports.ConnectableObservable = ConnectableObservable; |
| 80 |
//# sourceMappingURL=ConnectableObservable.js.map |