Upgrading to Elm 0.19

I upgraded to 0.18 to 0.19 recently, and it was harder / more annoying than I was hoping for. There wasn’t always documentation for the things, and I spent a reasonable amount of time looking at code on GitHub to work things out. I used https://github.com/avh4/elm-upgrade, which was very helpful.

Is this something a lot of people experience? And / or are a lot of people stuck on 0.18? If so perhaps as a community we could invest some time in the docs and in elm-upgrade?

Here are some of the things that I learned that I think aren’t easily available.

eeue56/elm-html-test is now elm-explorations/test

DateTime.parse is gone, the nearest equivalent is Iso8601.toTime, but it only works with Iso 8601 formatted dates (this might cause you a breaking change).

‘date’ is replaced by ‘datetime’ in ‘Json.Decode.Extra’, but it only works with Iso 8601 formatted dates (this might cause you a breaking change).

Date.Extra is now Time.Extra

  • Date.Extra.toFormattedString is gone, use date-format instead.
  • Date.Extra.compare is gone, but is trivial to implement
  • Date.Extra.fromCalendarDate is replaced by Time.Extra.partsToPosix

Some things in style-elements are different

  • Style.Color is replacEd by Color.Color
  • Style.rgba uses 0 - 1 to specify the color, whereas Color.rgba used 0 - 255, so if all your colors are white, this is why.

Window.size doesn’t exist any more, which I was using to get the initial window size. You now do this in javascript and pass in as a flag. Window.reSizes is now Browser.Events.onResize. This has width and height parameters instead of a Size type.

Location is repalced by Url

  • parsePath is replaced by parse
  • absolute is used to create urls, and does the encoding
  • Http.decodeUri becomes Url.percentDecode. The docs say not to use this and to use Url instead, but I didn’t find a way to persuade this to give me a human formatted string.

Browser.Key is annoying, and causes code damage (it has benefits too). I created a ModelAndKey type, and I try and limit the damage to as close to the entry point of the application as possible.

I used Browser.application to take over the entire page, which requires some changes to the static pages.

  • index.html requires <body id="page-body"> instead of <div id="root"></div>
  • index.js requires import { Elm } from './Main.elm'; instead of import { Main ...
  • index.js requires Elm.Main.init({...}) instead of Main.embed(document.getElementById('root'), {...})
6 Likes

Yes, lots of (good!) changes, especially with dates, and quite a bit of work. I personally found it cathartic, as it was nice to finally get rid of some Native code.

The old 0.18 dates were JS dates (which suck). That was probably one of the biggest changes.

I ended up basically swapping the old Elm dates for justinmimbs/date

https://package.elm-lang.org/packages/justinmimbs/date/latest/

which is amazing (thanks @justinmimbs!), then converting bits to the new Time library as needed (e.g. elm-visualization now requires Posix values for the time axes).

Also, see rtfeldman/elm-iso8601-date-strings and as you mentioned ryannhg/date-format, which conceptually a cool library, but should maybe be called time-format, as it requires a Posix, not a date.

The thing to watch out for is that Time and Date are not the same things (kinda duh, but not entirely obvious).

For example, if you convert a date like 2001-01-01 to time, you’ll get a UTC time of 0:00:00, then if you use the date-format library to format that time, you need to provide a timezone.

If you’re in the US, that will shift by at least 5 hours, so it will format as “December 31, 2000”, so in general, if you are working with actual dates as opposed to timestamps (which is really what the new Time library is), probably better to just use Date.fomat "MMM d, y" date

Also color–I swapped out for avh4/elm-color

I ended up not using Browser.application and used Browser.element, as we use Phoenix/Elixir to handle sessions, login,etc.

Yes to all the other things!

Also:

  • Json.Decode.list changed signature (wants a decoder and a list, not a list of decoded objects).
  • Style changed from a list of tuples to a single function, e.g. Style "font-weight" "bold"
  • Hash parsing hack
  • Regex changes (no more Regex All, etc.)
  • Can no longer do stuff like Json.Decode.map2 (,), need to do Json.Decode.map2 Tuple.pair

It took me 7 solid days to do the upgrade.

Rock on,

3 Likes

If you do need to parse date/time strings like "Fri, 11 Jan 2013 08:11:00 GMT" to Posix values, then there is dmy/elm-imf-date-time as well.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.