Skip to content

Commit

Permalink
refactor: use delete to remove the member
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Jun 3, 2020
1 parent 18c0ef8 commit e3f1417
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/internal/Subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,7 @@ export class Subscription implements SubscriptionLike {
*/
constructor(unsubscribe?: () => void) {
if (unsubscribe) {
// Wrap the unsubscribe teardown in a function so that the argument can
// be nulled. 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.
(<any> this)._unsubscribe = () => {
unsubscribe!();
unsubscribe = undefined;
};
(this as any)._unsubscribe = unsubscribe;
}
}

Expand All @@ -66,13 +57,20 @@ export class Subscription implements SubscriptionLike {
return;
}

let { _parentOrParents, _unsubscribe, _subscriptions } = (<any> this);
let { _parentOrParents, _unsubscribe, _subscriptions } = (this as any);

this.closed = true;
this._parentOrParents = null;
// 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 Down Expand Up @@ -140,7 +138,7 @@ export class Subscription implements SubscriptionLike {
add(teardown: TeardownLogic): Subscription {
let subscription = (<Subscription>teardown);

if (!(<any>teardown)) {
if (!teardown) {
return Subscription.EMPTY;
}

Expand Down

0 comments on commit e3f1417

Please sign in to comment.