Recently my Elm Chromecast app stopped working on Android. I just tracked it down to a string constant changing on the JS side. chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED was “ORIGIN_SCOPED” and changed to “origin_scoped”. Of course in Elm I just have
originScoped : AutoJoinPolicy
originScoped =
"origin_scoped"
I’d really like to just refer to the JS constant directly so this kind of thing can’t happen again. How would I do that?
You can pass in JS-constants to your Elm app using flags (see programWithFlags
), and storing it in your model.
1 Like
This seems non-trivial. I want to pass a record that contains a bunch of constants with NAMES_LIKE_THIS, which Elm barfs on. Which may imply some JSON decoding or my munging the values before passing them in?
You can use Decoder
for Flags
. Just define main
as Program Value model msg
(where Value is Value from Json module) and use decode
in init
.
1 Like