Re: [elm-discuss] Dynamic implementation resolving

2016-08-23 Thread Larry Weya
Brilliant, why didn't I think of that :) Thanks, that makes it much more concise. On Tuesday, 23 August 2016 20:18:00 UTC+3, Nick H wrote: > > Apologies, your update function would actually look like this: > > update : Msg -> Model -> Model > update message model = > case (message, m

Re: [elm-discuss] Dynamic implementation resolving

2016-08-23 Thread Nick H
Apologies, your update function would actually look like this: update : Msg -> Model -> Model update message model = case (message, model) of (CreateInvoiceMsg msg, CreateInvoiceImpl data) -> CreateInvoice.update msg data (SendTextMsg msg, SendTextImpl data) -> SendText.upda

Re: [elm-discuss] Dynamic implementation resolving

2016-08-23 Thread Nick H
I am not sure what you mean by routing to an implementation "in a generic way". You can clean up your code a lot by merging your "Model" type with "Impl". This is the more idiomatic way of writing in Elm: type alias Model = CreateInvoiceImpl CreateInvoice.Model | SendTextImpl SendTex

Re: [elm-discuss] Dynamic implementation resolving

2016-08-23 Thread Larry Weya
Thank you for the response, routing to the proper implementation in a generic way is my problem. The command implementation should receive the json value and take care of decoding it. I ended up implementing it using case expressions which is ok but means I need to update the module in a number

Re: [elm-discuss] Dynamic implementation resolving

2016-08-23 Thread Nick H
This sounds like exactly the use case for Json.Decode.andThen . (See that documentation for an example) Your could have your main module decode the JSON "params" enough to figure out which type of message you've received

[elm-discuss] Dynamic implementation resolving

2016-08-22 Thread Larry Weya
I have a project where I would like to have different implementations depending on a provided value. I have what we are referring to as Commands and we are using elm provide a UI used to configure a command's parameters so e.g. we have 2 Commands, a CreateInvoice command and a SendText command.