Skip to content

Instantly share code, notes, and snippets.

@leojpod
Last active May 22, 2017 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leojpod/7ab41db6a12551ac0f7b4c91e961f611 to your computer and use it in GitHub Desktop.
Save leojpod/7ab41db6a12551ac0f7b4c91e961f611 to your computer and use it in GitHub Desktop.
App's state file
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