PatrickJS / angular-hmr

:fire: Angular Hot Module Replacement for Hot Module Reloading
https://patrickjs.com
Apache License 2.0
505 stars 46 forks source link

Q: how does reload exactly work. #78

Closed nojaf closed 5 years ago

nojaf commented 5 years ago

Hi, I'm coming from a react background and used hmr in things like create-react-app.

I've currently have hmr configured in my angular app, but it works a bit different than I expected.

So I make a change inside a file, HMR kicks in but it reloads my entire angular app. My main module gets reloaded and events like route changed get replayed as well. The behavior is very much similar to when you refresh the entire page. Except with HMR the html and other stuff is still loaded.

Is this the way it is supposed to work? Or should I create angular modules and will only those be reloaded when files changes?

PatrickJS commented 5 years ago

yup, this works as intended since it's the least amount of work without messing with angular internals like wrapping providers etc. also see "Hot Reloading in React or, an Ode to Accidental Complexity" https://medium.com/@dan_abramov/hot-reloading-in-react-1140438583bf

if you want to persist state you can use the store object on destroy

nojaf commented 5 years ago

Thanks for the explanation. I already persisted my state in sessionStorage.