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);
9 return function (d, b) {
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var Subscriber_1 = require("../Subscriber");
18 return function refCountOperatorFunction(source) {
19 return source.lift(new RefCountOperator(source));
22 exports.refCount = refCount;
23 var RefCountOperator = (function () {
24 function RefCountOperator(connectable) {
25 this.connectable = connectable;
27 RefCountOperator.prototype.call = function (subscriber, source) {
28 var connectable = this.connectable;
29 connectable._refCount++;
30 var refCounter = new RefCountSubscriber(subscriber, connectable);
31 var subscription = source.subscribe(refCounter);
32 if (!refCounter.closed) {
33 refCounter.connection = connectable.connect();
37 return RefCountOperator;
39 var RefCountSubscriber = (function (_super) {
40 __extends(RefCountSubscriber, _super);
41 function RefCountSubscriber(destination, connectable) {
42 var _this = _super.call(this, destination) || this;
43 _this.connectable = connectable;
46 RefCountSubscriber.prototype._unsubscribe = function () {
47 var connectable = this.connectable;
49 this.connection = null;
52 this.connectable = null;
53 var refCount = connectable._refCount;
55 this.connection = null;
58 connectable._refCount = refCount - 1;
60 this.connection = null;
63 var connection = this.connection;
64 var sharedConnection = connectable._connection;
65 this.connection = null;
66 if (sharedConnection && (!connection || sharedConnection === connection)) {
67 sharedConnection.unsubscribe();
70 return RefCountSubscriber;
71 }(Subscriber_1.Subscriber));
72 //# sourceMappingURL=refCount.js.map