Hi Mads, Many many thanks for your gist.
Surely your code worked just fine, but it also gave me a lot to study — probably I'm going back to it many times these days : ) Hell yeah! Thank you very much, On Tue, Jun 14, 2016 at 6:13 PM Mads Flensted-Urech <[email protected]> wrote: > Ok - disregard my comment on the seconds, was a little bit to hasty there. > > Here is a gist > <https://gist.github.com/madsflensted/083e8555ada9db4c8b324f7e79eabd0f> > that will fetch the time from your API and decode it. > > On Tue, Jun 14, 2016 at 9:50 PM, Mads Flensted-Urech < > [email protected]> wrote: > >> Hi Eduardo. >> >> the easiest way to get one-time configuration from the JS world is via >> the progamWithFlags , see the docs here: >> http://package.elm-lang.org/packages/elm-lang/html/1.0.0/Html-App#programWithFlags >> >> I know it is not a direct answer to your question of making HTTP >> requests. But it may get you going. Otherwise follow the HTTP section of >> the Elm guide <http://guide.elm-lang.org/architecture/effects/http.html> >> >> I just briefly looked over your code, and it seems that you are really >> only using the *seconds* to update your model, so you could probably get >> by with simply JSON decoding the seconds returned from your API. >> >> >> >> On Tue, Jun 14, 2016 at 6:35 PM, Eduardo Cuducos <[email protected]> >> wrote: >> >>> Hi all, >>> >>> I'm a newbie in Elm — and I already love it. Is this list suitable for >>> beginners with (probably the silliest) doubts? If not, my apologies, delete >>> this email and move on ; ) >>> >>> I'm writing a stopwatch >>> <https://github.com/cuducos/cunhajacaiu/blob/elm/cunhajacaiu/static/elm/Stopwatch.elm> >>> to study Elm — replacing something in a legacy tiny project that used to be >>> in ReactJS. (In other news: this study project made me write a webassets >>> filter to compile Elm >>> <https://twitter.com/cuducos/status/742698891343204353> files, hello >>> Python world). >>> >>> The stopwatch itself is working fine. I load it in the proper DOM >>> element and it starts counting seconds, minutes, hours, days etc… >>> >>> However I would like to set a starting count for the stopwatch — that is >>> to say, instead of staring with* 0 days, 0 hours, 0 minutes and 0 >>> seconds*, I would like it to start with (for example) *33 days, 20 >>> hours, 17 minutes and 45 seconds*. >>> >>> I would load this data from an API >>> <http://www.cunhajacaiu.com.br/api/stopwatch/> (JSON) or from the DOM >>> itself: >>> >>> <div id="stopwatch" >>> data-days="57" >>> data-hours="13" >>> data-minutes="7" >>> data-seconds="2"> >>> ... >>> </div> >>> >>> First I thought that loading from the API was easier, but to run the >>> HTTP request and parse the JSON was a bit troublesome for a beginner. >>> >>> Then I tried to use *ports*: I defined a ports module, but couldn't get >>> my types right. For examples, one of the things I tried: >>> >>> -- snippet from ports module >>> port load : { days: Int , hours: Int , minutes: Int , seconds: Int } -> >>> Cmd >>> >>> Got me: >>> >>> 4| port load : { days: Int , hours: Int , minutes: Int , seconds: Int } >>> -> Cmd >>> >>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >>> You are saying it should be: >>> >>> { days : Int, hours : Int, minutes : Int, seconds : Int } >>> -> Platform.Cmd.Cmd >>> >>> But you need to use the particular format described here: >>> <http://guide.elm-lang.org/effect_managers/> >>> >>> And honestly I couldn't figure out how this URL would help me. >>> >>> Just in case, In my Javascript I had: >>> >>> var stopwatchContainer = document.getElementById('stopwatch'); >>> if (stopwatchContainer !== null) { >>> var app = Elm.Stopwatch.embed(stopwatchContainer); >>> app.ports.load.send(stopwatchContainer.dataset); >>> } >>> >>> Any idea on how to implement that (whether it is via API or ports)? >>> Replies, links, chats, pair programming, pull requests… anything is more >>> than welcomed ; ) >>> >>> Many thanks, >>> >>> Eduardo Cuducos >>> http://cuducos.me/ >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Elm Discuss" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> > -- > You received this message because you are subscribed to the Google Groups > "Elm Discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
