Created
March 24, 2017 11:12
-
-
Save s-m-i-t-a/d202f4c1fe83b41ea5c3497c284bd36c to your computer and use it in GitHub Desktop.
Dispatcher function for elm update functions.
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 Update exposing (dispatch) | |
{-| Create update function | |
updater1 : Msg -> Model -> Maybe Model | |
updater1 msg model = | |
case msg of | |
Foo -> | |
Just { model | foo = "Foo" } | |
_ -> | |
Nothing | |
updater2 : Msg -> Model -> Maybe Model | |
updater2 msg model = | |
case msg of | |
Bar -> | |
Just { model | bar = "Bar" } | |
_ -> | |
Nothing | |
updaters : List (Msg -> Model -> Maybe Model) | |
updaters = | |
[ updater1 | |
, updater2 | |
] | |
main : Program Never Model Msg | |
main = | |
Html.beginnerProgram | |
{ model = init | |
, view = view | |
, update = dispatch updaters msg model | |
} | |
-} | |
dispatch : List (msg -> model -> Maybe model) -> msg -> model -> model | |
dispatch updaters msg model = | |
case updaters of | |
[] -> | |
model | |
f :: fs -> | |
case f msg model of | |
Just model -> | |
model | |
Nothing -> | |
dispatch fs msg model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment