I'm porting an application from React/Redux to Elm and I'm having trouble 
figuring out how to format a value as money. In the original application we 
used http://openexchangerates.github.io/accounting.js/. So naturally I 
wanted to make use of that same library when writing the Elm version. Based 
on my reading ports seem to be the solution however when I think through 
the implications it doesn't seem natural to write my code in that way when 
formatting is a presentation concern.

Here's what I came up with:

1. I created a port module called Format.

port module Format exposing (..)
>
> port asMoney : Float -> Cmd msg
> port moneyFormats : (String -> msg) -> Sub msg


2. I originally envisioned writing the view as follows:

viewSales : Float -> Html Msg
> viewSales amount =
>     viewWidget "Gross Sales (All Time)" (Format.asMoney amount)


But obviously, that's out the window since Format.asMoney returns a command.

3. It means I now have to format in my update function and store the 
formatted data in my model so that my view can access it. I find that very 
inconvenient and I don't want presentation concerns in neither my update 
function nor my model.

Am I thinking through this correctly?

How do I proceed?

Should I consider writing an external library with a Native module like for 
e.g. https://github.com/NoRedInk/elm-moment 
or https://github.com/evancz/elm-graphics?

Any help would be greatly appreciated.

-- 
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.

Reply via email to