first commit
This commit is contained in:
commit
35db20b196
4 changed files with 93 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
elm-stuff/
|
||||||
|
repl-temp-*
|
26
Counter.elm
Normal file
26
Counter.elm
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import Html exposing (Html, button, div, text)
|
||||||
|
import Html.App as Html
|
||||||
|
import Html.Events exposing (onClick)
|
||||||
|
|
||||||
|
main : Program Never
|
||||||
|
main = Html.beginnerProgram { model = model
|
||||||
|
, view = view
|
||||||
|
, update = update
|
||||||
|
}
|
||||||
|
|
||||||
|
type alias Model = Int
|
||||||
|
model : Model
|
||||||
|
model = 0
|
||||||
|
|
||||||
|
type Msg = Increment | Decrement
|
||||||
|
|
||||||
|
update : Msg -> Model -> Model
|
||||||
|
update msg model = case msg of
|
||||||
|
Increment -> model + 1
|
||||||
|
Decrement -> model - 1
|
||||||
|
view : Model -> Html Msg
|
||||||
|
view model = div []
|
||||||
|
[ button [ onClick Decrement ] [text "-"]
|
||||||
|
, div [] [text (toString model)]
|
||||||
|
, button [ onClick Increment ] [text "+"]
|
||||||
|
]
|
50
Main.elm
Normal file
50
Main.elm
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
import Html exposing (Html, button, div, text)
|
||||||
|
import Html.App as App
|
||||||
|
import Time exposing (Time,second)
|
||||||
|
import Html.Events exposing (onClick)
|
||||||
|
|
||||||
|
main : Program Never
|
||||||
|
main = App.program { init = init
|
||||||
|
, view = view
|
||||||
|
, update = update
|
||||||
|
, subscriptions = subscriptions
|
||||||
|
}
|
||||||
|
|
||||||
|
-- MODEL
|
||||||
|
|
||||||
|
type alias Model = { money : Int
|
||||||
|
, t : Time
|
||||||
|
}
|
||||||
|
|
||||||
|
init : (Model,Cmd Msg)
|
||||||
|
init = ({ money = 0
|
||||||
|
, t = 0
|
||||||
|
}, Cmd.none)
|
||||||
|
|
||||||
|
-- UPDATE
|
||||||
|
|
||||||
|
type Msg = Gain Int | Tick Time | Reset
|
||||||
|
|
||||||
|
update : Msg -> Model -> (Model, Cmd Msg)
|
||||||
|
update msg model =
|
||||||
|
let newmodel = case msg of
|
||||||
|
Gain i -> { model | money = (model.money + i) }
|
||||||
|
Tick newTime -> { model | money = model.money + (if model.t > 0
|
||||||
|
then truncate ((newTime - model.t) / 1000)
|
||||||
|
else 0)
|
||||||
|
, t = newTime }
|
||||||
|
Reset -> { model | money = 0 }
|
||||||
|
in (newmodel,Cmd.none)
|
||||||
|
|
||||||
|
-- SUBSCRIPTION
|
||||||
|
|
||||||
|
subscriptions : Model -> Sub Msg
|
||||||
|
subscriptions model = Time.every second Tick
|
||||||
|
|
||||||
|
view : Model -> Html Msg
|
||||||
|
view model = div []
|
||||||
|
[ button [ onClick (Gain 1) ] [text "+1"]
|
||||||
|
, button [ onClick (Gain 2) ] [text "+2"]
|
||||||
|
, div [] [text (toString (.money model))]
|
||||||
|
, button [ onClick Reset ] [text "0"]
|
||||||
|
]
|
15
elm-package.json
Normal file
15
elm-package.json
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"summary": "helpful summary of your project, less than 80 characters",
|
||||||
|
"repository": "https://github.com/user/project.git",
|
||||||
|
"license": "BSD3",
|
||||||
|
"source-directories": [
|
||||||
|
"."
|
||||||
|
],
|
||||||
|
"exposed-modules": [],
|
||||||
|
"dependencies": {
|
||||||
|
"elm-lang/core": "4.0.3 <= v < 5.0.0",
|
||||||
|
"elm-lang/html": "1.1.0 <= v < 2.0.0"
|
||||||
|
},
|
||||||
|
"elm-version": "0.17.1 <= v < 0.18.0"
|
||||||
|
}
|
Loading…
Reference in a new issue