Last active
May 22, 2017 12:56
-
-
Save leojpod/7ab41db6a12551ac0f7b4c91e961f611 to your computer and use it in GitHub Desktop.
App's state file
This file contains 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
init : ( Model, Cmd Msg ) | |
init = | |
let | |
( subModuleInitModel, subModuleInitCommand ) = | |
SubModule.State.init | |
-- repeat for any submodule you have | |
model = Model subModuleInitModel ... -- init your model here | |
cmd = Cmd.batch [ subModuleInitCommand, ... ] -- init your commands here | |
in | |
( model, cmd ) | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
BoardMsg boardMsg -> | |
Board.State.update boardMsg model.board | |
|> (\( newBoard, _ ) -> ( { model | board = newBoard }, Cmd.none )) | |
SetupMsg setupMsg -> | |
Setup.State.update setupMsg model.setup | |
|> (\( newSetup, cmd ) -> ( { model | setup = newSetup }, Cmd.none )) | |
SomeOtherModuleMsg theActualMsg -> | |
SomeOtherModule.State.update theActualMsg model.someOtherModule | |
-- here we just feed the submodule's update function our app's "instance" of the model | |
|> (\( newSubModuleModel, someAssociatedCommand) -> | |
( { model | someOtherModule = newSubModuleModel}, someAssociatedCommand) | |
Mdl mdlMsg -> | |
Material.update Mdl mdlMsg model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment