Last active
October 23, 2015 16:13
-
-
Save mkulke/ae0343ac9ccd55c6d903 to your computer and use it in GitHub Desktop.
elm playground
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
import Graphics.Element exposing (..) | |
import Signal exposing (..) | |
import Time exposing (..) | |
import Keyboard exposing (..) | |
type alias Model = Int | |
initialModel : Model | |
initialModel = 1 | |
type Action = Noop | |
| Increment Int | |
actions : Mailbox Action | |
actions = | |
mailbox Noop | |
model : Signal Model | |
model = | |
Signal.foldp update initialModel | |
(Signal.mergeMany [actions.signal, timer, keyboard]) | |
update : Action -> Model -> Model | |
update action model = | |
case action of | |
Increment n -> | |
model + n | |
main : Signal Element | |
main = | |
map show model | |
keyboard : Signal Action | |
keyboard = | |
Signal.map | |
(\t -> Increment 10) | |
Keyboard.presses | |
timer : Signal Action | |
timer = | |
Signal.map | |
(\t -> Increment 1) | |
(every second) |
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
module EventLog where | |
import Html exposing (..) | |
import Http exposing (..) | |
-- import Task exposing (..) | |
import Html.Events exposing (..) | |
import Html.Attributes exposing (..) | |
import Signal exposing (..) | |
import Constants exposing (Resource, gabi) | |
-- import Json.Decode as Json exposing (..) | |
-- getProcess : Task Http.Error (List String) | |
-- getProcess = | |
-- Http.get idAndName gabi.url | |
-- idAndName : Json.Decoder (String, String) | |
-- idAndName = | |
-- object2 (,) | |
-- ("id" := id) | |
-- ("age" := Json.Decode.string) | |
type alias Model = | |
{ events : List String | |
, input : String | |
} | |
actions: Mailbox Action | |
actions = | |
mailbox Noop | |
initialModel : Model | |
initialModel = | |
{ events = [] | |
, input = "my input" | |
} | |
model: Signal Model | |
model = | |
foldp update initialModel actions.signal | |
main : Signal Html | |
main = | |
Signal.map (view actions.address) model | |
type Action = Noop | |
| Mark String | |
| Reset | |
| MarkInput | |
| UpdateInput String | |
update : Action -> Model -> Model | |
update action model = | |
case action of | |
Mark date -> | |
{ model | events <- model.events ++ [date] } | |
Reset -> | |
{ model | events <- [] } | |
MarkInput -> | |
{ model | events <- model.events ++ [model.input] } | |
UpdateInput date -> | |
{ model | input <- date } | |
onInput : Signal.Address a -> (String -> a) -> Attribute | |
onInput address contentToValue = | |
on "input" targetValue (\str -> Signal.message address (contentToValue str)) | |
view : Address Action -> Model -> Html | |
view address model = | |
div [] | |
[ button [ onClick address (Mark "?") ] [ text "Mark" ], | |
button [ onClick address Reset ] [ text "Reset" ], | |
button [ onClick address MarkInput ] [ text "MarkInput" ], | |
input [ value model.input, onInput address UpdateInput ] [], | |
h2 [] [ text (model.events |> List.length |> toString), text " Events" ], | |
div [] (List.map (\t -> text t) model.events), | |
h2 [] [ text "Ajax Result" ], | |
button [ onClick address (Mark gabi.url) ] [ text "Fetch" ] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment