This package makes it easier to build (module, Cmd msg)
, the typical result of an update function
withCmd : Platform.Cmd.Cmd msg -> model -> ( model, Platform.Cmd.Cmd msg )
Pack a cmd with your model
model
|> withCmd cmd
withCmds : List (Platform.Cmd.Cmd msg) -> model -> ( model, Platform.Cmd.Cmd msg )
Pack multiple cmds with your model
model
|> withCmds [ cmd0, cmd1 ]
withNoCmd : model -> ( model, Platform.Cmd.Cmd msg )
Pack your model with no cmd
model
|> withNoCmd
withModel : model -> Platform.Cmd.Cmd msg -> ( model, Platform.Cmd.Cmd msg )
Pack a model with your cmd. This is useful if the business logic for your command is more complicated than the business logic for your model
Close ->
model.sessionId
|> Ports.Close
|> Ports.send
|> withModel model
addCmd : Platform.Cmd.Cmd msg -> ( model, Platform.Cmd.Cmd msg ) -> ( model, Platform.Cmd.Cmd msg )
Sometimes you need to add a cmd to an already packaged model and cmd.
(model, cmd0)
|> addCmd cmd1
-- == (model, Cmd.batch [ cmd1, cmd0 ])
addCmds : List (Platform.Cmd.Cmd msg) -> ( model, Platform.Cmd.Cmd msg ) -> ( model, Platform.Cmd.Cmd msg )
Add many cmds to an already packaged model and cmd.
(model, cmd0)
|> addCmds [ cmd1, cmd2 ]
-- == (model, Cmd.batch [ cmd0, cmd1, cmd2 ])
mapModel : (a -> b) -> ( a, Platform.Cmd.Cmd msg ) -> ( b, Platform.Cmd.Cmd msg )
If you need to transform just the model in a tuple, such as if you need to pack a submodel into the main model
loginModel
|> Login.update subMsg
|> mapModel (setPage model Page.Login)
mapCmd : (a -> b) -> ( model, Platform.Cmd.Cmd a ) -> ( model, Platform.Cmd.Cmd b )
If you need to transform just the cmd in a tuple, such as if you need to wrap a sub-modules msg type
loginModel
|> Login.update subMsg
|> mapCmd LoginMsg
model : ( model, Platform.Cmd.Cmd msg ) -> model
Ideally you wouldnt have to deconstruct a tupled model and cmd, but if you need to, this function does it.
Return2.model (model, cmd) == model
cmd : ( model, Platform.Cmd.Cmd msg ) -> Platform.Cmd.Cmd msg
Get the cmd of an already tupled model and cmd.
Return2.cmd (model, cmd) == cmd