Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created April 3, 2016 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/046a2402401cd4e3573d2bc26bce3221 to your computer and use it in GitHub Desktop.
Save chuck0523/046a2402401cd4e3573d2bc26bce3221 to your computer and use it in GitHub Desktop.
update : Action -> Model -> Model
update action model =
case action of
Insert ->
let newCounter = ( model.nextID, Counter.init 0 )
newCounters = model.counters ++ [ newCounter ]
in
{ model |
counters = newCounters,
nextID = model.nextID + 1
}
Remove id ->
{ model |
counters = List.filter (\(counterID, _) -> counterID /= id) model.counters
}
Modify id counterAction ->
let updateCounter (counterID, counterModel) =
if counterID == id
then (counterID, Counter.update counterAction counterModel)
else (counterID, counterModel)
in
{ model | counters = List.map updateCounter model.counters }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment