Skip to content

Instantly share code, notes, and snippets.

@TheSeamau5
Created May 21, 2015 23:53
Show Gist options
  • Save TheSeamau5/5c26a31356f6cd0ac647 to your computer and use it in GitHub Desktop.
Save TheSeamau5/5c26a31356f6cd0ac647 to your computer and use it in GitHub Desktop.
import Signal exposing (Signal)
import Html exposing (Html)
import Time
import Random exposing (Generator)
import Json.Decode exposing (Decoder)
import Json.Encode exposing (Value)
type alias Encoder a = a -> Value
mock
: { model : model
, view : model -> view
, update : action -> model -> model
, actions : Generator action
}
-> Signal view
mock {model, view, update, actions} =
let
makeSeed time =
Random.initialSeed (time * 1000000)
makeAction seed =
Random.generate actions seed
|> fst
counter =
Signal.foldp (\x y -> y + 1) 0 (Time.fps 60)
signal =
Signal.map (makeSeed >> makeAction) counter
in
Signal.foldp update model signal
|> Signal.map view
--
update action state = action + state
view state =
Html.span
[]
[ Html.text (toString state) ]
model = 0
actions = Random.int -2 2
main =
mock
{ model = model
, view = view
, update = update
, actions = actions
}
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment