The bigger deal in your question is your mention of OnDestroy. That does not work the same way in Ionic as it does in Angular, and I don’t recommend using it at all, for anything. Instead, if you want to destroy a page, pop it off the nav stack. If you can’t do that naturally, assume it’s around forever.
Let’s examine your stance. The page is around until you pop it off the nav stack. Yes, I agree. I think you’re right about that. Now from this, you then conclude that if you don’t pop it off the nav stack, the page is around “forever” which I will assume is a hyperbolic way to say as long as your app is running.
Then you reason that because of this, OnDestroy
should not be used “at all, for anything.” You furthermore conclude “use the word “subscribe” almost never.”
My response to this is we’ve now named multiple ways that both the page doesn’t need to hang around during the entire app lifetime and that any Subscriptions to Observables don’t need to hang around either.
We’ve collected the following methods:
- unsubscribe in OnDestroy and pop the page off the nav stack
- Use take, takeUntil, or takeWhile on the observable
I’ll also mention you can unsubscribe from the Observable at any other reasonable point.
Finally, there are some Observables like the Angular Http get and post methods, that will only emit one response anyway, so there’s no need to unsubscribe AFAIK.
For these reasons, while I appreciate the thoughts, I just don’t agree that I should never use OnDestroy, at all, for anything or that I should use the word subscribe almost never in my code.