Last active
August 29, 2015 14:25
-
-
Save TheSeamau5/53a4b5fc6d3cbf0dedae 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
import Html exposing (Html) | |
import Signal exposing (Address) | |
type alias Vector = | |
{ x : Float , y : Float } | |
---------------------------------- | |
type alias Init options state effect = options -> (state, effect) | |
type alias Update action state effect = action -> state -> (state, effect) | |
type alias View action state = Address action -> state -> Html | |
type alias Component options action state effect = | |
{ init : Init options state effect | |
, update : Update action state effect | |
, view : View action state | |
} | |
-- How to run a component | |
run : options -> Component options action state effect -> (Signal Html, Signal effect) | |
run options component = | |
let | |
--initial : (state, effect) | |
initial = | |
component.init options | |
--mailbox : Mailbox (Maybe action) | |
mailbox = | |
Signal.mailbox Nothing | |
--update : Maybe action -> (state, effect) -> (state, effect) | |
update maybeAction (state, effect) = | |
case maybeAction of | |
Nothing -> | |
(state, effect) | |
Just action -> | |
component.update action state | |
--result : Signal (state, effect) | |
result = | |
Signal.foldp update initial mailbox.signal | |
--states : Signal state | |
states = | |
Signal.map fst result | |
--effects : Signal effect | |
effects = | |
Signal.map snd result | |
--actionAddress : Address action | |
actionAddress = | |
Signal.forwardTo mailbox.address Just | |
--htmls : Signal Html | |
htmls = | |
Signal.map (component.view actionAddress) states | |
in | |
(htmls, effects) | |
type alias ContainerList context options action state effect | |
= Update context state effect | |
-> Component options action state effect | |
-> Component (Options options) | |
(Action action) | |
(State state) | |
(Effect effect) | |
type alias Container2 context1 options1 action1 state1 effect1 | |
context2 options2 action2 state2 effect2 | |
= Update context1 state1 effect1 -> Component options1 action1 state1 effect1 | |
-> Update context2 state2 effect2 -> Component options2 action2 state2 effect2 | |
-> Component (Options options1 options2) | |
(Action action1 action2) | |
(State state1 state2) | |
(Effect effect1 effect2) | |
type alias Container3 context1 options1 action1 state1 effect1 | |
context2 options2 action2 state2 effect2 | |
context3 options3 action3 state3 effect3 | |
= Update context1 state1 effect1 -> Component options1 action1 state1 effect1 | |
-> Update context2 state2 effect2 -> Component options2 action2 state2 effect2 | |
-> Update context3 state3 effect3 -> Component options3 action3 state3 effect3 | |
-> Component (Options options1 options2 options3) | |
(Action action1 action2 actions3) | |
(State state1 state2 state3) | |
(Effect effect1 effect2 effect3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment