Skip to content

Commit

Permalink
fix: chain safe subscribers to interop subscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Jun 9, 2020
1 parent 4439308 commit a9eaae8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/internal/Subscriber.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isFunction } from './util/isFunction';
import { empty as emptyObserver } from './Observer';
import { Observer, PartialObserver } from './types';
import { Subscription } from './Subscription';
import { Subscription, isSubscription } from './Subscription';
import { rxSubscriber as rxSubscriberSymbol } from '../internal/symbol/rxSubscriber';
import { config } from './config';
import { hostReportError } from './util/hostReportError';
Expand Down Expand Up @@ -187,8 +187,8 @@ export class SafeSubscriber<T> extends Subscriber<T> {
complete = (<PartialObserver<T>> observerOrNext).complete;
if (observerOrNext !== emptyObserver) {
context = Object.create(observerOrNext);
if (isFunction(context.unsubscribe)) {
this.add(<() => void> context.unsubscribe.bind(context));
if (isSubscription(observerOrNext)) {
observerOrNext.add(this.unsubscribe.bind(this));
}
context.unsubscribe = this.unsubscribe.bind(this);
}
Expand Down
6 changes: 6 additions & 0 deletions src/internal/Subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ export class Subscription implements SubscriptionLike {
}
}

export function isSubscription(value: object): value is Subscription {
return value &&
typeof (value as any).add === 'function' &&
typeof (value as any).unsubscribe === 'function';
}

function flattenUnsubscriptionErrors(errors: any[]) {
return errors.reduce((errs, err) => errs.concat((err instanceof UnsubscriptionError) ? err.errors : err), []);
}

0 comments on commit a9eaae8

Please sign in to comment.