Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Subscription): remove will now remove any teardown by reference #5659

Merged

Conversation

benlesh
Copy link
Member

@benlesh benlesh commented Aug 20, 2020

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:

const teardown = () => console.log('called');

const subscription = new Subscription();

subscription.add(teardown);
subscription.remove(teardown);
subscription.unsubscribe();

// Will log nothing

Similarly with "unsubscribables":

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

Description:

Related issue (if exists):

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
@benlesh benlesh requested a review from cartant August 20, 2020 00:11
spec/Subscriber-spec.ts Show resolved Hide resolved
src/internal/Subscription.ts Outdated Show resolved Hide resolved
src/internal/Subscription.ts Outdated Show resolved Hide resolved
src/internal/Subscription.ts Outdated Show resolved Hide resolved
src/internal/Subscription.ts Outdated Show resolved Hide resolved
src/internal/Subscription.ts Show resolved Hide resolved
- 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
@benlesh benlesh requested a review from cartant August 20, 2020 13:44
Copy link
Collaborator

@cartant cartant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a couple of nitpicks.

src/internal/Subscription.ts Outdated Show resolved Hide resolved
src/internal/Subscription.ts Outdated Show resolved Hide resolved
@benlesh benlesh merged commit 1531152 into ReactiveX:master Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants