1 /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Subscriber } from '../Subscriber';
4 export function refCount() {
5 return function refCountOperatorFunction(source) {
6 return source.lift(new RefCountOperator(source));
9 var RefCountOperator = /*@__PURE__*/ (function () {
10 function RefCountOperator(connectable) {
11 this.connectable = connectable;
13 RefCountOperator.prototype.call = function (subscriber, source) {
14 var connectable = this.connectable;
15 connectable._refCount++;
16 var refCounter = new RefCountSubscriber(subscriber, connectable);
17 var subscription = source.subscribe(refCounter);
18 if (!refCounter.closed) {
19 refCounter.connection = connectable.connect();
23 return RefCountOperator;
25 var RefCountSubscriber = /*@__PURE__*/ (function (_super) {
26 tslib_1.__extends(RefCountSubscriber, _super);
27 function RefCountSubscriber(destination, connectable) {
28 var _this = _super.call(this, destination) || this;
29 _this.connectable = connectable;
32 RefCountSubscriber.prototype._unsubscribe = function () {
33 var connectable = this.connectable;
35 this.connection = null;
38 this.connectable = null;
39 var refCount = connectable._refCount;
41 this.connection = null;
44 connectable._refCount = refCount - 1;
46 this.connection = null;
49 var connection = this.connection;
50 var sharedConnection = connectable._connection;
51 this.connection = null;
52 if (sharedConnection && (!connection || sharedConnection === connection)) {
53 sharedConnection.unsubscribe();
56 return RefCountSubscriber;
58 //# sourceMappingURL=refCount.js.map