Skip to content

Commit

Permalink
remove not needed subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mpodlasin committed Mar 13, 2017
1 parent 270f2ad commit 1c5282a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class Observable<T> implements Subscribable<T> {
if (operator) {
operator.call(sink, this.source);
} else {
sink.addParentTeardown(this._trySubscribe(sink));
sink.addParentTeardownLogic(this._trySubscribe(sink));
}

if (sink.syncErrorThrowable) {
Expand Down
15 changes: 8 additions & 7 deletions src/Subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Subscriber<T> extends Subscription implements Observer<T> {
public syncErrorThrown: boolean = false;
public syncErrorThrowable: boolean = false;

private parentSubscription: Subscription = new Subscription();
private parentSubscription: Subscription | null = null;

protected isStopped: boolean = false;
protected destination: PartialObserver<any>; // this `any` is the escape hatch to erase extra type param (e.g. R)
Expand Down Expand Up @@ -71,7 +71,7 @@ export class Subscriber<T> extends Subscription implements Observer<T> {
if (typeof destinationOrNext === 'object') {
if (destinationOrNext instanceof Subscriber) {
this.destination = (<Subscriber<any>> destinationOrNext);
(<any> this.destination).add(this);
(<Subscriber<any>> this.destination).addParentTeardownLogic(this);
} else {
this.syncErrorThrowable = true;
this.destination = new SafeSubscriber<T>(this, <PartialObserver<any>> destinationOrNext);
Expand All @@ -85,13 +85,14 @@ export class Subscriber<T> extends Subscription implements Observer<T> {
}
}

addParentTeardown(parentTeardown: TeardownLogic) {
this.parentSubscription.add(parentTeardown);
this.add(this.parentSubscription);
addParentTeardownLogic(parentTeardownLogic: TeardownLogic) {
this.parentSubscription = this.add(parentTeardownLogic);
}

unsubscribeParentSubscription() {
this.parentSubscription.unsubscribe();
if (this.parentSubscription !== null) {
this.parentSubscription.unsubscribe();
}
}

/**
Expand Down Expand Up @@ -167,7 +168,7 @@ export class Subscriber<T> extends Subscription implements Observer<T> {
this.isStopped = false;
this._parent = _parent;
this._parents = _parents;
this.parentSubscription = new Subscription();
this.parentSubscription = null;
return this;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/observable/dom/WebSocketSubject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,8 @@ export class WebSocketSubject<T> extends AnonymousSubject<T> {
if (!this.socket) {
this._connectSocket();
}
let subscription = new Subscription();
subscription.add(this._output.subscribe(subscriber));
subscription.add(() => {
this._output.subscribe(subscriber);
subscriber.add(() => {
const { socket } = this;
if (this._output.observers.length === 0) {
if (socket && socket.readyState === 1) {
Expand All @@ -261,7 +260,7 @@ export class WebSocketSubject<T> extends AnonymousSubject<T> {
this._resetState();
}
});
return subscription;
return subscriber;
}

unsubscribe() {
Expand Down

0 comments on commit 1c5282a

Please sign in to comment.