klazuka / elm-hot

Hot module reloading for Elm
Other
74 stars 17 forks source link

Cannot make it work with elm-spa-example #13

Closed rlopzc closed 6 years ago

rlopzc commented 6 years ago

Can this work with this model?

klazuka commented 6 years ago

I haven’t tried that SPA example, but I recently published a new version of elm-hot-webpack-loader (1.0.1) that should work (it will search for a Browser.Navigation.Key anywhere in your model, even in the variants of a custom type).

Please confirm that you have the latest version of both elm-hot-webpack-loader and elm-hot, and then give it a try and follow-up here. Thanks.

rlopzc commented 6 years ago

Hi, I made this but didn't work. Am I missing something?

https://github.com/romariolopezc/elm-webpack-4-starter/pull/43

The home page has a counter when you click in the heading. I see that it tries to inject the changes but the browser doesn't change a thing

klazuka commented 6 years ago

@romariolopezc I checked out your example. There are 2 things wrong, none of them have to do with Richard's SPA app architecture:

1) you are using Browser.application, but in your index.js you are calling Elm init and providing a DOM node to takeover. But that's not necessary since Browser.application will always take over the body, not the node that you provide. 2) elm-hot trusts that the node you pass to init is accurate, but it shouldn't.

For (1), you should remove the "main" div from your index.html and then in index.js, invoke Elm as just Elm.Main.init(); (or you can pass it an empty object if you want).

For (2), I created issue #14, and I'll fix it.

I'm glad we found this bug, though :-)

rlopzc commented 6 years ago

Awesome, thanks for the info!