Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created April 16, 2016 10:40
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/a300a979e316076a2acd83f858a3e15f to your computer and use it in GitHub Desktop.
Save chuck0523/a300a979e316076a2acd83f858a3e15f to your computer and use it in GitHub Desktop.
update : Action -> Model -> Model
update action model =
case action of
Add ->
let newTodo = ( model.nextID, Todo.init model.nextID model.addText )
newTodos = model.todos ++ [ newTodo ]
in
{ model |
todos = newTodos,
nextID = model.nextID + 1,
addText = ""
}
InputText str ->
{ model |
addText = str
}
Modify id todoAction ->
let updateTodo (todoId, todoModel) =
if todoId == id
then (todoId, Todo.update todoAction todoModel)
else (todoId, todoModel)
in
{ model |
todos = List.map updateTodo model.todos
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment