1 import { Subscriber } from '../Subscriber';
2 export function refCount() {
3 return function refCountOperatorFunction(source) {
4 return source.lift(new RefCountOperator(source));
7 class RefCountOperator {
8 constructor(connectable) {
9 this.connectable = connectable;
11 call(subscriber, source) {
12 const { connectable } = this;
13 connectable._refCount++;
14 const refCounter = new RefCountSubscriber(subscriber, connectable);
15 const subscription = source.subscribe(refCounter);
16 if (!refCounter.closed) {
17 refCounter.connection = connectable.connect();
22 class RefCountSubscriber extends Subscriber {
23 constructor(destination, connectable) {
25 this.connectable = connectable;
28 const { connectable } = this;
30 this.connection = null;
33 this.connectable = null;
34 const refCount = connectable._refCount;
36 this.connection = null;
39 connectable._refCount = refCount - 1;
41 this.connection = null;
44 const { connection } = this;
45 const sharedConnection = connectable._connection;
46 this.connection = null;
47 if (sharedConnection && (!connection || sharedConnection === connection)) {
48 sharedConnection.unsubscribe();
52 //# sourceMappingURL=refCount.js.map