Hello and thanks for reading.
So, the scenario I had to implement was a service that opens up a web-socket which is required by a component. That component tells the user what’s the network latency — green <50ms yellow 300ms and red for more than 300 ms, based on a web-socket connection.
That component can be toggled on and off by the user ( by default off) and wanting to keep the requests to a minimum I wanted to initialize the web-socket only when I needed it.
All that plus the confusion that a service can have onDestroy
but calls it at a different time than a component’s onDestroy
is what led to me wanting to share with the world my finding.
Generally, the scenario is a stateful service that should die with the component it serves. In my case, the state was the web socket connection.
Does that make sense?
What do you use services for?
(Disclaimer: This was a really long time ago — around 3 years now — so the specific details are a bit blurry and the code is no longer available to me…)