rgrempel / elm-route-url

Router for single-page-apps in Elm
http://package.elm-lang.org/packages/rgrempel/elm-route-url/latest
MIT License
196 stars 16 forks source link

Update from Elm 0.18's Navigation.program to Elm 0.19's Browser.application #38

Open jerith666 opened 5 years ago

jerith666 commented 5 years ago

fixes #37.

lenards commented 5 years ago

Hey @jerith666, if you want any help with this, I would like to see this upgraded.

jerith666 commented 5 years ago

Great! If you want to propose updates to the docs and examples, I can review and hopefully we can wrap this up! :)

FWIW I've been using git submodules to work with this in 0.19 while I await its completion. See https://github.com/jerith666/elbum/commit/49873d62c964fcadb2c03d640a09abb7bbce1ca3. It might be nice to see a second example of this working in a real app, via that mechanism, before we declare it done too.

lenards commented 5 years ago

Okay.

On Wed, Jan 16, 2019 at 9:13 PM Matt McHenry notifications@github.com wrote:

Great! If you want to propose updates to the docs and examples, I can review and hopefully we can wrap this up! :)

FWIW I've been using git submodules to work with this in 0.19 while I await its completion. See jerith666/elbum@49873d6 https://github.com/jerith666/elbum/commit/49873d62c964fcadb2c03d640a09abb7bbce1ca3. It might be nice to see a second example of this working in a real app, via that mechanism, before we declare it done too.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rgrempel/elm-route-url/pull/38#issuecomment-455036301, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAXI_S38RsCwt9FuKjWDn9g0CGqF7I4ks5vD_h6gaJpZM4ZZZvG .

lenards commented 5 years ago

I've been shifted to other work, so I have not had a chance to look at this yet.

On Wed, Jan 16, 2019 at 9:24 PM Andrew Lenards andrew.lenards@gmail.com wrote:

Okay.

On Wed, Jan 16, 2019 at 9:13 PM Matt McHenry notifications@github.com wrote:

Great! If you want to propose updates to the docs and examples, I can review and hopefully we can wrap this up! :)

FWIW I've been using git submodules to work with this in 0.19 while I await its completion. See jerith666/elbum@49873d6 https://github.com/jerith666/elbum/commit/49873d62c964fcadb2c03d640a09abb7bbce1ca3. It might be nice to see a second example of this working in a real app, via that mechanism, before we declare it done too.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rgrempel/elm-route-url/pull/38#issuecomment-455036301, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAXI_S38RsCwt9FuKjWDn9g0CGqF7I4ks5vD_h6gaJpZM4ZZZvG .

basti1302 commented 4 years ago

I realize this PR has been dormant for a long while, so maybe the momentum to land this is no longer there. However, I recently revived an old Elm 0.17 app and upgraded it first to 0.18 and then to 0.19.1 (using @jerith666 's fork as a submodule as suggested), so I thought I might share a bit of feedback around that.

I had a bit of a hard time figuring out why programWithFlags requires passing an onUrlRequest handler now and what to do in it exactly. To my (maybe naive) understanding, the RouteUrl module would/should/could handle url request (like, clicking on a link that takes you to another page in your app etc.). Thus it should be enough to provide delta2url and location2messages, as we did in Elm 0.18.

I started with providing a no-op handler there, that is onUrlRequest = \urlRequest -> NoOp, where NoOp is a message of my app that does nothing in update. With that in place, the app would compile, but of course, clicking on a link like <a href="#some-fragment">go somewhere else</a> would now longer work now.

I think it would be more intuitive if at least internal UrlRequests would be handled directly in elm-route-url, like this: https://github.com/basti1302/elm-route-url/commit/aeef0e7b645fae7360bb42b59f776ad53808aadb

This directly wraps internal url requests into a RouterMsg(which is then implicitly fed to RouteUrl#update), so the app does not need to take care of them.

I'm undecided on external UrlRequest, maybe those still should be passed on to the application that is using elm-route-url.

An alternative solution would be leave the onUrlRequest as it is now in this PR and just have the app turn it into a RouteMsg on its own – maybe there apps with use cases that require additional actions to be taken even for internal URL requests? But then elm-route-url needs to expose a way to create RouteMsg and feed them back into RouteUrl#update. Actually, wrapLocation already exposes a way to create those but: a. its comment suggests that a client app is not actually supposed to use it (except for testing), and b. I'm not sure how this could type check successfully as the app's onUrlRequest needs to return the Msg type of the app and can not return elm-route-url's WrappedMsg type.

Of course, it is totally possible that I am holding this wrong and missing something obvious.

jerith666 commented 4 years ago

Thanks for the feedback!

I just looked through how I have onUrlRequest implemented in my app, and I think what you propose would work okay there. I'd have to move things around, but I suspect the result might turn out to be simpler in the end -- it would definitely remove a pushUrl call in my code that just gets turned right around into another RouterMsg AFAICT.

I do still need to see the external URLs in my app, and I think the way you've done that with onExternalUrlRequest also seems right.

If it's okay, I'll take some time to rework my app to use this, and confirm my intuition. If it turns out the way I expect, I'll add your change to this PR!

jerith666 commented 4 years ago

Just an update: I still think this will work, but it needs an important tweak. As you've implemented it, there's nothing that causes the Browser.Navigation.pushUrl call that's needed to actually update the URL. So we need to account for that. I think the approach I've taken in https://github.com/jerith666/elm-route-url/commit/32a3a0c552426cfa0a7820ec71eda62a21a59d1a will do the trick. But it's tangled up with some other unrelated changes I'd been working on, so I need to take some time to disentangle it for inclusion here.

jerith666 commented 4 years ago

Finally got some time to update the examples & README, and squash down to a single commit with a sensible message. Please take a look and let me know if I've missed anything!

lenards commented 4 years ago

I think you got everything in your well-crafted commit message. Thanks for that.

Also, just want to note that I appreciate the --debug being used in the examples.