-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Subscription): remove will now remove any teardown by reference (#…
…5659) * feat(Subscription): remove will now remove any teardown by reference Previously, only `Subscription` instances could be removed from a `Subscription`. Now any valid `TeardownLogic` that has been added to a `Subscription` may be removed by passing the same instance to `add`. For example: ```ts const teardown = () => console.log('called'); const subscription = new Subscription(); subscription.add(teardown); subscription.remove(teardown); subscription.unsubscribe(); // Will log nothing ``` Similarly with "unsubscribables": ```ts const unsubscribable = { unsubscribe() { console.log('called'); } }; const subscription = new Subscription(); subscription.add(unsubscribable); subscription.remove(unsubscribable); subscription.unsubscribe(); // Will log nothing ``` - Cleans up and refactors Subscription substantially. - Adds a few additional tests around Subscription and checking for teardown registries and unregistries * refactor: Address comments - Addresses comments - Refines code a little further, moving some work closer to where it needs to be (teardowns array will no longer be allocated before we see if we even need to add anything, etc) - Rewrites conditionals in _addParent method. - Fixes test that didn't really test anything * refactor: Remove unused declarations * chore: address comments
- Loading branch information
Showing
9 changed files
with
300 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** @prettier */ | ||
import { TeardownLogic } from 'rxjs'; | ||
|
||
export function getRegisteredTeardowns(subscription: any): Exclude<TeardownLogic, void>[] { | ||
if ('_teardowns' in subscription) { | ||
return subscription._teardowns ?? []; | ||
} else { | ||
throw new TypeError('Invalid Subscription'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.