Created
September 2, 2015 21:13
-
-
Save TheSeamau5/efef97ed21b160cd3875 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 Init options state effect | |
= options -> (state, List effect) | |
type alias Update action state effect | |
= action -> state -> (state, List 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 | |
} | |
simple : { init : state | |
, update : action -> state -> state | |
, view : state -> Html | |
} | |
-> Component Void action state Never | |
simple {init, update, view} = | |
{ init = always (init, []) | |
, update = (\a s -> (update a s, [])) | |
, view = always view | |
} | |
container : { child : context -> Component childOptions childAction childState childEffect | |
, init : (context -> Init childOptions childState childEffect) -> Init options state effect | |
, update : (context -> Update childAction childState childEffect) -> Update action state effect | |
, view : (context -> View childAction childState) -> View action state | |
} | |
-> Component options action state effect | |
container {child, init, update, view} = | |
{ init = init (child >> .init) | |
, update = update (child >> .update) | |
, view = view (child >> .view) | |
} | |
container2 : { child1 : context1 -> Component child1Options child1Action child1State child1Effect | |
, child2 : context2 -> Component child2Options child2Action child2State child2Effect | |
, init : (context1 -> Init child1Options child1State child1Effect) | |
-> (context2 -> Init child2Options child2State child2Effect) | |
-> Init options state effect | |
, update : (context1 -> Update child1Action child1State child1Effect) | |
-> (context2 -> Update child2Action child2State child2Effect) | |
-> Update action state effect | |
, view : (context1 -> View child1Action child1State) | |
-> (context2 -> View child2Action child2State) | |
-> View action state | |
} | |
-> Component options action state effect | |
container2 {child1, child2, init, update, view} = | |
{ init = init (child1 >> .init) (child2 >> .init) | |
, update = update (child1 >> .update) (child2 >> .update) | |
, view = view (child1 >> .view) (child2 >> .view) | |
} | |
simpleContainer : { child : Component childOptions childAction childState childEffect | |
, init : Init childOptions childState childEffect -> Init options state effect | |
, update : Update childAction childState childEffect -> Update action state effect | |
, view : View childAction childState -> View action state | |
} | |
-> Component options action state effect | |
simpleContainer {child, init, update, view} = | |
{ init = init child.init | |
, update = update child.update | |
, view = view child.view | |
} | |
simpleContainer2 : { child1 : Component child1Options child1Action child1State child1Effect | |
, child2 : Component child2Options child2Action child2State child2Effect | |
, init : Init child1Options child1State child1Effect | |
-> Init child2Options child2State child2Effect | |
-> Init options state effect | |
, update : Update child1Action child1State child1Effect | |
-> Update child2Action child2State child2Effect | |
-> Update action state effect | |
, view : View child1Action child1State | |
-> View child2Action child2State | |
-> View action state | |
} | |
-> Component options action state effect | |
simpleContainer2 {child1, child2, init, update, view} = | |
{ init = init child1.init child2.init | |
, update = update child1.update child2.update | |
, view = view child1.view child2.view | |
} | |
type Never = Never Never | |
type Void = Void | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment