Last active
January 17, 2016 19:17
-
-
Save danyx23/36800cf83bae03485732 to your computer and use it in GitHub Desktop.
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
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