-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicTodoList.elm
53 lines (39 loc) · 1.03 KB
/
BasicTodoList.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Html exposing (Html, div, button, text)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick)
import String
main =
beginnerProgram { model = model, view = view, update = update }
-- MODEL
type alias Task = { task : String, complete : Bool }
tasks : List Task
tasks =
[
{ task = "Buy milk", complete = True }
, { task = "Drink milk", complete = False }
]
type alias Model = String
model : Model
model =
""
-- UPDATE
type Visibility = All | Active | Completed
update : Visibility -> Model -> Model
update msg model =
(case msg of
All ->
tasks
Active ->
List.filter (\task -> not task.complete) tasks
Completed ->
List.filter (\task -> task.complete) tasks)
|> List.map .task |> String.join " and "
-- VIEW
view : Model -> Html Visibility
view model =
div []
[ button [ onClick All ] [ text "All" ]
, button [ onClick Active ] [ text "Active" ]
, button [ onClick Completed ] [ text "Completed" ]
, div [] [ text (toString model) ]
]