Skip to content

Commit

Permalink
refactor: delete _unsubscribe only if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Jun 3, 2020
1 parent e3f1417 commit 2cc8171
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/internal/Subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ export class Subscription implements SubscriptionLike {
// null out _subscriptions first so any child subscriptions that attempt
// to remove themselves from this subscription will noop
this._subscriptions = null;
// It's not possible to null the _unsubscribe member as there are many
// classes that are derived from Subscriber (which derives from
// Subscription) that implement an _unsubscribe method as a mechanism for
// obtaining unsubscription notifications and some of those subscribers are
// recycled. Deleting the member will release the reference to any teardown
// functions passed in the constructor and will leave any methods intact.
delete (this as any)._unsubscribe;

if (_parentOrParents instanceof Subscription) {
_parentOrParents.remove(this);
Expand All @@ -82,6 +75,14 @@ export class Subscription implements SubscriptionLike {
}

if (isFunction(_unsubscribe)) {
// It's not possible to null the _unsubscribe member as there are many
// classes that are derived from Subscriber (which derives from
// Subscription) that implement an _unsubscribe method as a mechanism for
// obtaining unsubscription notifications and some of those subscribers
// are recycled. Deleting the member will release the reference to any
// teardown functions passed in the constructor and will leave any
// methods intact.
delete (this as any)._unsubscribe;
try {
_unsubscribe.call(this);
} catch (e) {
Expand Down

0 comments on commit 2cc8171

Please sign in to comment.