PersonType and PersonTypeSpecificValues can be combined into one type:
type alias Model =
{ person : Person }
type Person
= Individual IndividualFields
| Company CompanyFields
As for how to handle model updates, I think there are a few things to
consider. What types of updates are possible? Are the sorts of updates
allowed with companies & individuals very similar or very different? How do
we transition from having an Individual to having a Company, and vice versa?
Depending on the answers to these questions, you might not want to split
the IndividualFields and CompanyFields into separate modules. At least not
right away.
But that said, here is one way you could delegate actions to sub-models:
type Action =
IndividualAction IndividualFields.Action
| CompanyAction CompanyFields.Action
update action model =
case (action, model) of
(IndividualAction a, Individual fields) ->
Individual (IndividualFields.update a fields)
(CompanyAction a, Company fields) ->
Company (CompanyFields.update a fields)
_ ->
model
view model =
case model of
Individual fields ->
IndividualFields.view fields
|> Html.map IndividualAction
Company fields ->
CompanyFields.view fields
|> Html.map CompanyAction
On Wed, Nov 23, 2016 at 12:49 PM, Vlad GURDIGA wrote:
> Hey guys! 8-)
>
> I’m playing with an app for bailiffs. For the data entry UI I need a
> PersonSection widget to enter the data for a party that participates in a
> case. So a person can be either an individual or a company, so I’m
> imagining this as: a “Person type” dropdown + a set of person-type-specific
> fields.
>
> So, the model looks like this:
>
> type alias Model =
> { personType : PersonType
> , personTypeSpecificFieldValues : PersonTypeSpecificValues
> }
>
> type PersonType =
> = Individual
> | Company
>
> type PersonTypeSpecificValues
> = IndividualFieldValues IndividualFields.Model
> | CompanyFieldValues CompanyFields.Model
>
> I have extracted the corresponding pieces of model structure and view into
> IndividualFields.elm and CompanyFields.elm, but I don’t know how to extract
> the model updates. The code here: https://github.com/
> gurdiga/elm-play/blob/master/Main.elm.
>
> I have checked a similar example from the “Elm Beyond The Basics” course
> here: https://github.com/knowthen/elm-beyond-basics/blob/master/01The-Elm-
> Architecture/Main.elm but my case is a bit different: depending on
> personType I’m trying to alternatively store any of the two field value
> sets (IndividualFieldValues or CompanyFieldValues) into a single model
> member (personTypeSpecificFieldValues), although I’m not sure this is a
> good idea.
>
> I’m wondering what’d be an idiomatic approach to build this widget.
>
> Cheers!
>
> --
> 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 elm-discuss+unsubscr...@googlegroups.com.
> 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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.