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

refactor(Subscription): Get rid of _unsubscribe weirdness #5670

Conversation

benlesh
Copy link
Member

@benlesh benlesh commented Aug 23, 2020

This is just another step toward getting what we're doing with inheritance to be a little more sane, ultimately, this may be refactored further, as I am not happy with some of these subscribers adding their own teardowns, but this is a start. The goal was to get rid of the weirdness around _unsubscribe in our code base.

  • Moves to calling _unsubscribe a new internal name in Subscription: initialTeardown, because it's slightly more descriptive
  • Removes _unsubscribe usage from the entire code base.
  • Formatted a few files just for my sanity.

This is just another step toward getting what we're doing with inheritance to be a little more sane, ultimately, this may be refactored further, as I am not happy with some of these subscribers adding their own teardowns, but this is a start. The goal was to get rid of the weirdness around `_unsubscribe` in our code base.

- Moves to calling `_unsubscribe` a new internal name in `Subscription`: `initialTeardown`, because it's slightly more descriptive
- Removes `_unsubscribe` usage from the entire codebase.
- Formatted a few files just for my sanity.
@benlesh benlesh requested a review from cartant August 23, 2020 21:22
@benlesh
Copy link
Member Author

benlesh commented Aug 23, 2020

In retrospect, I might be able to just have a private intialTeardown = () => property on those that are doing this.add(this._teardown)... but again, one thing at a time. I'm trying to be incremental, but I could do that in this PR, I suppose. After an initial review.

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.

One suggestion/question (in multiple places) and one nitpick.

src/internal/Subscriber.ts Show resolved Hide resolved
(this as any)._unsubscribe = unsubscribe;
}
}
constructor(private initialTeardown?: () => void) {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

🎉

src/internal/Subscription.ts Outdated Show resolved Hide resolved
src/internal/operators/refCount.ts Show resolved Hide resolved
@@ -80,6 +80,7 @@ class WindowSubscriber<T> extends SimpleOuterSubscriber<T, any> {

constructor(destination: Subscriber<Observable<T>>) {
super(destination);
this.add(this._teardown);
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: (as above) this.add(this._teardown.bind(this))?

src/internal/operators/windowCount.ts Show resolved Hide resolved
@@ -90,6 +90,7 @@ class WindowToggleSubscriber<T, O> extends ComplexOuterSubscriber<T, any> {
private openings: Observable<O>,
private closingSelector: (openValue: O) => Observable<any>) {
super(destination);
this.add(this._teardown);
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: (as above) this.add(this._teardown.bind(this))?

src/internal/scheduler/AsyncAction.ts Show resolved Hide resolved
@benlesh benlesh merged commit fd1e039 into ReactiveX:master Aug 25, 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