@@ -0,0 +1,132 @@
7+-- The full application state of our todo app.
12+ , visibility : String
17+ { description : String
24+newTask : String -> Int -> Task
44+-- A description of the kinds of actions that can be performed on the model of
45+-- our application. See the following post for more info on this pattern and
46+-- some alternatives: http://elm-lang.org/learn/Architecture.elm
50+ | EditingTask Int Bool
51+ | UpdateTask Int String
57+ | ChangeVisibility String
60+-- How we update our Model on a given Action?
61+update : Action -> Model -> Model
68+ uid <- model.uid + 1,
71+ if String.isEmpty model.field
73+ else model.tasks ++ [newTask model.field model.uid]
77+ { model | field <- str }
79+ EditingTask id isEditing ->
80+ let updateTask t = if t.id == id then { t | editing <- isEditing } else t
82+ { model | tasks <- List.map updateTask model.tasks }
84+ UpdateTask id task ->
85+ let updateTask t = if t.id == id then { t | description <- task } else t
87+ { model | tasks <- List.map updateTask model.tasks }
90+ { model | tasks <- List.filter (\t -> t.id /= id) model.tasks }
93+ { model | tasks <- List.filter (not << .completed) model.tasks }
95+ Check id isCompleted ->
96+ let updateTask t = if t.id == id then { t | completed <- isCompleted } else t
98+ { model | tasks <- List.map updateTask model.tasks }
100+ CheckAll isCompleted ->
101+ let updateTask t = { t | completed <- isCompleted }
103+ { model | tasks <- List.map updateTask model.tasks }
105+ ChangeVisibility visibility ->
106+ { model | visibility <- visibility }
110+ [ List.concatMap --Add 50 tasks
111+ (\i -> [UpdateField <| "My task " ++ toString i, Add]) [1 .. 50]
112+ , [CheckAll True] --Check them all
113+ , [CheckAll False] --Uncheck them all
114+ , List.concatMap --Alter the text of even numbered tasks
115+ (\i -> [EditingTask i True, UpdateTask i "New Task text", Add] ) <| List.filter (\x -> x % 2 == 0 ) [1 .. 50]
116+ --Check and uncheck some more tasks
117+ , [Check 5 True, Check 7 True, Check 9 True, Check 13 True, Check 17 True, Check 23 True, Check 37 True]
118+ , [Check 7 False, Check 13 False, Check 23 False, Check 37 False]
119+ , [DeleteComplete] --Delete our checked tasks
120+ , [Delete 7, Delete 23] --Delete a few more tasks
121+ , List.concatMap --Add a few more tasks
122+ (\i -> [UpdateField <| "Second batch task " ++ toString i, Add]) [51 .. 80]
123+ , List.map --Check off and delete every other task
124+ (\i -> Check i True ) <| List.filter List.filter (\x -> x % 2 == 0 ) [1 .. 80]
126+ , [CheckAll True, DeleteComplete] --Check and delete the remaining tasks
130+evalActions : List Action -> Model
131+evalActions actions =
132+ List.foldr update emptyModel actions