lukeed / svelte-demo

Multi-page demo built Svelte 3.x and Rollup with code-splitting
MIT License
114 stars 19 forks source link

Usefulness of onDestory method in App component #5

Closed frederikhors closed 5 years ago

frederikhors commented 5 years ago

I was wondering about this line of code:

https://github.com/lukeed/svelte-demo/blob/44a94f3c005c0d186ee584b5f125dceac0362b1d/src/components/App.svelte#L43

Is it really useful to have a listener for this?

The onDestroy() method is called when component (App.svelte) is being destroyed, so in this case it never happens, right?

lukeed commented 5 years ago

In the demo, as is, it never happens. But that doesn't mean it never happens in general.

Purposefully showing that the router needs to be detached on exit. Better safe than sorry