Skip to content

Instantly share code, notes, and snippets.

@danyx23
Last active January 17, 2016 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danyx23/36800cf83bae03485732 to your computer and use it in GitHub Desktop.
Save danyx23/36800cf83bae03485732 to your computer and use it in GitHub Desktop.
module CustomStartApp where
import Debug
import Html exposing (Html)
import Signal exposing (Address)
import Automaton exposing ((>>>))
type alias Config model action =
{ model : model
, view : Address action -> model -> Html
, update : action -> model -> model
}
start : Config model action -> Automaton.Automaton action action -> Signal Html
start config actionPreprocessor =
let
actions : Signal.Mailbox (Maybe action)
actions =
Signal.mailbox Nothing
address : Signal.Address (action)
address =
Signal.forwardTo actions.address Just
fromMaybeAutomaton : Automaton.Automaton (Maybe action) action
fromMaybeAutomaton = Automaton.pure (\maybe ->
case maybe of
Just content ->
content
Nothing ->
Debug.crash "This should never happen")
stateAutomaton : Automaton.Automaton action model
stateAutomaton = Automaton.state (config.model) config.update
automatonPipeline : Automaton.Automaton (Maybe action) model
automatonPipeline = fromMaybeAutomaton >>> actionPreprocessor >>> stateAutomaton
modelSignal = Automaton.run automatonPipeline (config.model) actions.signal
--model =
-- Signal.foldp update config.model actions.signal
in
Signal.map (config.view address) modelSignal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment