getArtist
: Int
-> (Result Http.Error Artist -> msg)
-> Cmd msg // <1>
getArtist id msg =
Http.get
(baseUrl ++ "/artists/" ++ toString id)
artistDecoder // <2>
❘> Http.send msg // <3>
21 November 2016
Tags: haskell elm haskellelmspa
TweetAnother Elm release and it’s time for yet another upgrade post. The changes outlined in the migration guide didn’t look to intimidating, so I jumped into it with pretty high confidence. It took me about 2 hours to get through and it was almost an instant success. The compiler had my back all along, helped by my editor showing errors inline and docs/signatures whenever I was in doubt. I didn’t even have to resort to google once to figure out what to do. I said it almost worked the first time. Well I had managed to add a http header twice which Servant wasn’t to impressed by, but once that was fixed everything was working hunky dory !
The Albums app is about 1400 lines of Elm code, so it’s small, but still it might give you some pointers to the effort involved when upgrading. With this upgrade I tried to be semi-structured in my commits so I’ll be referring to them as we go along.
Install Elm 0.18
Install elm-format
For this release @avh4 and @eeue56 created the very handy elm-upgrade util to ease the upgrade process.
To summarize what elm-upgrade does; It upgrades your project definition (elm-package.json) and it runs elm-format on your code in "upgrade mode" so that most of the syntax changes in core is fixed.
It worked great ! Only snag I had was that it failed to upgrade elm-community/json-extra, but hey that was simple enough for me to do afterwords. Here you can see the resulting diff. |
0.18 | 0.17 | ||||||
---|---|---|---|---|---|---|---|
|
|
If you wish to keep the old behavior, you can convert a request to a task using toTask |
0.18 | 0.17 | ||
---|---|---|---|
|
|
0.18 | 0.17 | ||||||
---|---|---|---|---|---|---|---|
|
|
0.18 | 0.17 | ||||
---|---|---|---|---|---|
|
|
You can view the complete diff for the Service Api here. (Please note that the headers for the put request should not be there, fixed in another commit) |
We’ll use the artist listing page as an example for handling the api changes. The big change is really that the messages have changed signature and we can remove a few.
0.18 | 0.17 | ||
---|---|---|---|
|
|
0.18 | 0.17 | ||||
---|---|---|---|---|---|
|
|
The diffs for the various pages can be found here: |
The url-parser package has had a few changes. Let’s have a closer look
0.18 | 0.17 | ||||||
---|---|---|---|---|---|---|---|
|
|
0.18 | 0.17 | ||||||
---|---|---|---|---|---|---|---|
|
|
0.18 | 0.17 |
---|---|
We get the initial url passed as a Location to the init function. We just delegate to the update function to handle the url to load the appropriate page. |
|
0.18 | 0.17 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
|
You can see the complete diff here |
Obviosuly there were quite a few changes, but none of the were really that big and to my mind all of the changed things for the better. Using elm-upgrade and the upgrade feature in elm-format really helped kick-start the conversion, I have great hopes for this getting even better in the future.
I haven’t covered the re-introduction of the debugger in elm-reactor, which was the big new feature in Elm 0.18.
In addition to Elm 0.18 being a nice incremental improvement, it has been great to see that the community has really worked hard to upgrade packages and helping out making the upgrade as smooth as possible. Great stuff !
A little mind-you that even though this simple app was easy to upgrade that might not be the case for you. But stories I’ve heard so far has a similar ring to them. I guess the biggest hurdle for upgrading is dependending on lot’s of third-party packages that might take some time before being upgraded to 0.18. Some patience might be needed. |