In Elm I have a model with nested attributes like:
model =
{ name = ""
, disruptedFields =
{ advertising =
{ name = "Advertising"
, checked = False
}
, travel =
{ name = "Travel"
, checked = False
}
, utilities =
{ name = "Utilities"
, checked = False
}
}
}
disruptedFields contains a list of values for checkboxes. When I click on the checkbox I send an update message to UpdateDisruptedField, which currently looks like:
UpdateDisruptedField value ->
let
fieldCollection = model.disruptedFields
field = fieldCollection.advertising
in
{ model | disruptedFields =
{ fieldCollection | advertising =
{ field | checked = (not value) }
}
}
My update function is hard-coded to model.disruptedField.advertising in the field and advertising variables. This is working for me, but I'm stuck making the function generic.
How do I pass the record into UpdateDisruptedField so I can make it generic?