On Sunday, March 26, 2017 at 10:57:46 PM UTC+1, Mark Hamburg wrote:
>
> I think I have some code that follows this pattern:
>
> module Mod exposing (Model, Msg, update)
>
> type Model = Model Imp
>
> type alias Imp = { ... private stuff goes here ... }
>
> update : Msg -> Model -> ( Model, Cmd Msg )
> update msg (Model imp) =
> updateImp msg imp |> rewrap
>
> rewrap : (Imp, x) -> (Model, x)
> rewrap (imp, x) =
> (Model imp, x)
>
>
>
> - A concern that this inhibits potential efficiency around cases where
> the update doesn't change the model but just results in additional commands
>
> Bear in mind that you don't have to unwrap/rewrap the model in this case.
The 'as' keyword lets you pattern match and keep the original at the same
time:
update msg (Model imp as model) =
case msg of
ThisOneUpdatesImp -> updateImp msg imp |> rewrap
| ThisOneDoesnt -> (model, someCmd)
--
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.