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 Subscriber_1 = require("../Subscriber");
|
---|
17 | function refCount() {
|
---|
18 | return function refCountOperatorFunction(source) {
|
---|
19 | return source.lift(new RefCountOperator(source));
|
---|
20 | };
|
---|
21 | }
|
---|
22 | exports.refCount = refCount;
|
---|
23 | var RefCountOperator = (function () {
|
---|
24 | function RefCountOperator(connectable) {
|
---|
25 | this.connectable = connectable;
|
---|
26 | }
|
---|
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();
|
---|
34 | }
|
---|
35 | return subscription;
|
---|
36 | };
|
---|
37 | return RefCountOperator;
|
---|
38 | }());
|
---|
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;
|
---|
44 | return _this;
|
---|
45 | }
|
---|
46 | RefCountSubscriber.prototype._unsubscribe = function () {
|
---|
47 | var connectable = this.connectable;
|
---|
48 | if (!connectable) {
|
---|
49 | this.connection = null;
|
---|
50 | return;
|
---|
51 | }
|
---|
52 | this.connectable = null;
|
---|
53 | var refCount = connectable._refCount;
|
---|
54 | if (refCount <= 0) {
|
---|
55 | this.connection = null;
|
---|
56 | return;
|
---|
57 | }
|
---|
58 | connectable._refCount = refCount - 1;
|
---|
59 | if (refCount > 1) {
|
---|
60 | this.connection = null;
|
---|
61 | return;
|
---|
62 | }
|
---|
63 | var connection = this.connection;
|
---|
64 | var sharedConnection = connectable._connection;
|
---|
65 | this.connection = null;
|
---|
66 | if (sharedConnection && (!connection || sharedConnection === connection)) {
|
---|
67 | sharedConnection.unsubscribe();
|
---|
68 | }
|
---|
69 | };
|
---|
70 | return RefCountSubscriber;
|
---|
71 | }(Subscriber_1.Subscriber));
|
---|
72 | //# sourceMappingURL=refCount.js.map |
---|