Created
August 23, 2018 21:53
-
-
Save sli/9001c24f4a8fad3338a42bf6b59daeae to your computer and use it in GitHub Desktop.
Some random, useless Elm shit that I just want to show to people.
This file contains hidden or 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
import Html exposing (Html, Attribute, text, program, section, div, button, input, label) | |
import Html.Events exposing (onClick) | |
import Html.Attributes exposing (class, type_, placeholder) | |
type alias Todo = | |
{ id : Int | |
, description : String | |
, done : Bool | |
} | |
type alias Model = { todos : List Todo } | |
type Msg | |
= Reset | |
| AddTodo { id : Int, description : String } | |
| RemoveTodo { id : Int } | |
| CheckTodo { id : Int } | |
init : ( Model, Cmd msg ) | |
init = ( { todos = [] }, Cmd.none ) | |
update : Msg -> Model -> ( Model, Cmd msg ) | |
update msg model = | |
let newModel = | |
case msg of | |
Reset -> { todos = [] } | |
AddTodo t -> { model | todos = { id = t.id, description = t.description, done = False } :: model.todos } | |
RemoveTodo t -> { model | todos = List.filter (\e -> e.id == t.id) model.todos } | |
CheckTodo t -> { model | todos = List.map (\e -> if e.id == t.id then { e | done = not e.done } else e) model.todos } | |
in | |
( newModel, Cmd.none ) | |
view : Model -> Html Msg | |
view model = | |
section [ class "section" ] | |
[ div [ class "field has-addons" ] | |
[ div [ class "control is-expanded" ] [ input [ class "input", type_ "text", placeholder "Description" ] [] ] | |
, div [ class "control" ] [ button [ class "button is-primary" ] [ text "Add Todo" ] ] | |
] | |
] | |
subscriptions : Model -> Sub Msg | |
subscriptions model = Sub.none | |
main = program | |
{ init = init | |
, update = update | |
, view = view | |
, subscriptions = subscriptions | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment