RxJS - rxMethods - do we need to explicity destroy #7553
dreamstar-enterprises
started this conversation in
Ideas / Feature request
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a signal store that has several rxMethods, within the withMehods block.
I understand that under the hood when an rxMethod is called, from a Component, the rxMethod will automatically subscribe to the observable that is in its return statement.
I also understand that this observable lives in the signal store where the rxMethod is defined.
What happens though if I navigate away to a new component and back to the component that then has a function that calls an rxMethod in the signal store. Will another observable be subscribed to? What if another different component calls the same rxMethod in that signal store? Will another observable be subscribed to?
Will these keep building up subscribed observables in the signal store?
Would the components have to somehow call the rxMethod.destroy() fn to clean up the observable?
Or is that something one call in the OnDestroy() method in the signal store itself, inside the WithHooks(), e.g. onDestroy() { rxMethod1.detroy(), rxMethod2.destroy() }
It's never really been clear to be when the rxMethod is subscribed (assuming automatically when called), and what happens when different components call the same rxMethod.
What might be the right way of ensuring proper clean up of any observables initiated?
Beta Was this translation helpful? Give feedback.
All reactions