Skip to content

Commit

Permalink
fix: Add dispose callback in operator call.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed May 14, 2020
1 parent bd9c2de commit 7f3dc40
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions source/operators/dispose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,8 @@ export function dispose<T>(callback: () => void): OperatorFunction<T, T> {
class DisposeOperator<T> implements Operator<T, T> {
constructor(private callback: () => void) {}
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
return source.subscribe(new DisposeSubscriber(subscriber, this.callback));
}
}

class DisposeSubscriber<T> extends Subscriber<T> {
constructor(destination: Subscriber<T>, private callback?: () => void) {
super(destination);
}
unsubscribe() {
super.unsubscribe();
const { callback } = this;
if (callback) {
callback();
this.callback = undefined;
}
const subscription = source.subscribe(subscriber);
subscription.add(this.callback);
return subscription;
}
}

0 comments on commit 7f3dc40

Please sign in to comment.