Automatically complete subjects #143
Replies: 20 comments 1 reply
-
until-destroy/src/lib/until-destroy.ts Line 18 in f03793a |
Beta Was this translation helpful? Give feedback.
-
It's been called. What's the issue? |
Beta Was this translation helpful? Give feedback.
-
Subjects are not completed, when calling I've made an example showing how the subject is not completed automatically, but subscriptions are: https://codesandbox.io/s/gallant-fast-i29fq?file=/src/app/components/subject.component.ts. Just click on the text and watch the console log when the subscription is completed, but not the subject. |
Beta Was this translation helpful? Give feedback.
-
That's related to how Rx works. When you call https://github.com/ReactiveX/rxjs/blob/master/src/internal/Subject.ts#L88 |
Beta Was this translation helpful? Give feedback.
-
It doesn't relate to the library. You can manually call it, and you'll get the same behavior. |
Beta Was this translation helpful? Give feedback.
-
So that line should be: (With extra many parentheses to make it a bit more clear) |
Beta Was this translation helpful? Give feedback.
-
Well, I don't want to do it manually. That's kind of the point. Now I have to find all subjects and manually complete them in my |
Beta Was this translation helpful? Give feedback.
-
I'm not sure we want this behavior. I'll leave it open for discussion. |
Beta Was this translation helpful? Give feedback.
-
@arturovt your opinion? |
Beta Was this translation helpful? Give feedback.
-
Unsubscribe !== complete |
Beta Was this translation helpful? Give feedback.
-
Why would you not want a component's subjects to be completed when the component is? If you complete the subject then you wouldn't have to unsubscribe all the places that subject is used.
Not sure what you are trying to say. I'm just saying that being able to automatically complete my subjects on component destroy would be a very nice feature that would make my life a lot easier. Just like the package has made my life easier when completing subscriptions. Whether it should be part of the |
Beta Was this translation helpful? Give feedback.
-
Because it will call |
Beta Was this translation helpful? Give feedback.
-
What I'm trying to say is that it's breaking the normal contract. |
Beta Was this translation helpful? Give feedback.
-
Introducing a new property wouldn't break any contracts. You could easily add something like |
Beta Was this translation helpful? Give feedback.
-
I'm afraid that would bring some inconsistent behavior since subjects have both $ node
{ Subject } = require('rxjs')
subject$ = new Subject()
subject$.unsubscribe()
subject$.complete() // Uncaught Error [ObjectUnsubscribedError]: object unsubscribed Checking that the isFunction(property, 'complete') && property.complete(); Because: I'll give you an example, in my applications there are many services that inherit @Injectable({ providedIn: 'root' })
export class SomeMicroFrontendBus extends Subject { ... } Thus calling |
Beta Was this translation helpful? Give feedback.
-
Don't add |
Beta Was this translation helpful? Give feedback.
-
You can add it in a backwards compatible way (by introducing a new property), so I don't see that as a problem. |
Beta Was this translation helpful? Give feedback.
-
True. But completing, then unsubscribing doesn't: subject = new Subject();
subject.complete();
subject.unsubscribe(); // no error You just ensure that you run them in the right order.
So can we just once and for all agree that making a new property would mean you could opt in, meaning you wouldn't have to do anything with your existing code? I would expect the blacklist to also apply in this case, of course. |
Beta Was this translation helpful? Give feedback.
-
Any comments? |
Beta Was this translation helpful? Give feedback.
-
Bit of a late community response, but we had a bit of a problem for a while because we assumed that We only have the use case where we create a |
Beta Was this translation helpful? Give feedback.
-
We often use subjects within components. Ensuring that they are correctly completed, when the component is destroyed is a bit cumbersome and people often forget it.
Would it be possible to
extend checkPropertiesadd a new property that could look for subjects and complete them?Beta Was this translation helpful? Give feedback.
All reactions