Last active
May 17, 2016 23:17
-
-
Save rogeriochaves/b85a6f4effe223793bd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
NoOp -> | |
model ! [] | |
Add -> | |
{ model | |
| uid = model.uid + 1 | |
, field = "" | |
, tasks = | |
if String.isEmpty model.field then | |
model.tasks | |
else | |
model.tasks ++ [newTask model.field model.uid] | |
} | |
! [] | |
UpdateField str -> | |
{ model | field = str } | |
! [] | |
EditingTask id isEditing -> | |
let | |
updateTask t = | |
if t.id == id then { t | editing = isEditing } else t | |
in | |
{ model | tasks = List.map updateTask model.tasks } | |
! [ focus ("#todo-" ++ toString id) ] | |
UpdateTask id task -> | |
let | |
updateTask t = | |
if t.id == id then { t | description = task } else t | |
in | |
{ model | tasks = List.map updateTask model.tasks } | |
! [] | |
Delete id -> | |
{ model | tasks = List.filter (\t -> t.id /= id) model.tasks } | |
! [] | |
DeleteComplete -> | |
{ model | tasks = List.filter (not << .completed) model.tasks } | |
! [] | |
Check id isCompleted -> | |
let | |
updateTask t = | |
if t.id == id then { t | completed = isCompleted } else t | |
in | |
{ model | tasks = List.map updateTask model.tasks } | |
! [] | |
CheckAll isCompleted -> | |
let | |
updateTask t = | |
{ t | completed = isCompleted } | |
in | |
{ model | tasks = List.map updateTask model.tasks } | |
! [] | |
ChangeVisibility visibility -> | |
{ model | visibility = visibility } | |
! [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment