This package makes it easier to build (module, Cmd msg, reply) a common return value for big sub-modules. See the readme for an explanation of what Return3 is all about.
Add a reply to your tuple.
model
|> R2.withNoCmd
|> R3.withReply UserNameChangedDont add a reply to your tuple.
FetchingData
|> R2.withCmd getLocalStorage
|> R3.withNoReplyIf building your reply takes a lot of work, use this function.
calculate width height x y
|> center model.size
|> UpdateSpace
|> R3.withTuple
(model |> R2.withNoCmd)Return the model with no cmd and no reply
model
|> withNothingSometimes you need to add a cmd to an already packaged Return
(model, cmd0, reply)
|> addCmd cmd1
-- == (model, Cmd.batch [ cmd1, cmd0 ], reply)Add many cmds to an already packaged Return
(model, cmd0, reply)
|> addCmds [ cmd1, cmd2 ]
-- == (model, Cmd.batch [ cmd0, cmd1, cmd2 ], reply)If you need to transform just the model in a Return, such as if you need to pack a submodel into the main model
loginModel
|> Login.update subMsg
|> mapModel (setPage model Page.Login)If you need to transform just the cmd in a Return, such as if you need to wrap a sub-modules msg type
loginModel
|> Login.update subMsg
|> mapCmd LoginMsgIdeally you wouldnt have to deconstruct a Return, but if you need to, this function does it.
Return3.model (model, cmd, Nothing) == modelGet the cmd of an already packed Return.
Return3.cmd (model, cmd, reply) == cmdGet the reply of an already packed Return, if it exists
Return3.reply (model, cmd, maybeReply) == maybeReplyReturns contain a reply, and that reply needs to be handled much like a msg does in an update function.
loginModel
|> Login.update loginMsg
|> R3.mapCmd LoginMsg
|> incorp handleLoginReply model
handleLoginReply : Login.Model -> Maybe Reply -> Model -> (Model, Cmd Msg)
handleLoginreply loginModel maybeReply model =
case maybeReply of
Nothing ->
{ model | page = Login loginModel }
|> R2.withNoCmd
Just (LoggedIn user) ->
{ model
| page = Home Home.init
, user = Just user
}
|> R2.withNoCmd
This alias formalizes that this particular triple is our return value.