the-sett / elm-update-helper / Update3Alt

Convenience function for lifting an update function for an inner model and messages, that also returns an additional out parameters into a parent one.

This version differs from Update3 by having the out messages in the second position in the return tuple, instead of the last.

lift : (model -> submodel) -> (submodel -> model -> model) -> (submsg -> msg) -> (submsg -> submodel -> ( submodel, outmsg, Platform.Cmd.Cmd submsg )) -> submsg -> model -> ( model, outmsg, Platform.Cmd.Cmd msg )

Lifts an update function of type:

update : submsg -> submodel -> ( submodel, Cmd submsg, outmsg )

Into one that returns:

( model, Cmd msg, outmsg )

eval : (outmsg -> model -> ( model, Platform.Cmd.Cmd msg )) -> ( model, outmsg, Platform.Cmd.Cmd msg ) -> ( model, Platform.Cmd.Cmd msg )

Allows the output of an update function that returns type:

( model, Cmd msg, outmsg )

To have its model and out message evaluated in order to produce a new model, and to create more commands. The commands returned will be appended to those passed in using Cmd.batch.

evalMaybe : (outMsg -> model -> ( model, Platform.Cmd.Cmd msg )) -> Platform.Cmd.Cmd msg -> ( model, Maybe outMsg, Platform.Cmd.Cmd msg ) -> ( model, Platform.Cmd.Cmd msg )

Allows the output of an update function that returns type:

( model, Cmd msg, outmsg )

To have its model and out message evaluated in order to produce a new model, and to create more commands. The commands returned will be appended to those passed in using Cmd.batch.

evalResult : (outMsg -> model -> ( model, Platform.Cmd.Cmd msg )) -> (error -> Platform.Cmd.Cmd msg) -> ( model, Result error outMsg, Platform.Cmd.Cmd msg ) -> ( model, Platform.Cmd.Cmd msg )

Allows the output of an update function that returns type:

   (model, Cmd msg, Maybe outmsg)

To have its model and out message evaluated in order to produce a new model, and to create more commands. The commands returned will be appended to those passed in using Cmd.batch.

evalCmds : (outmsg -> msg) -> ( model, Platform.Cmd.Cmd outmsg, Platform.Cmd.Cmd msg ) -> ( model, Platform.Cmd.Cmd msg )

Allows the output of an update function that returns type:

   (model, Cmd msg, Cmd outmsg)

To have its model and out message evaluated in order to produce a new model, and to create more commands. The commands returned will be appended to those passed in using Cmd.batch.

Note that the eval function in this case is not provided with the model, since the commands being processed are opaque, so it should not be possible to make a decision on how to update the model based on them.

mapModel : (model -> a) -> ( model, b, c ) -> ( a, b, c )

Maps over the model.

mapCmd : (msga -> msgb) -> ( a, b, Platform.Cmd.Cmd msga ) -> ( a, b, Platform.Cmd.Cmd msgb )

Maps over the Cmds

mapOutMsg : (outMsg -> c) -> ( a, outMsg, b ) -> ( a, c, b )

Maps over the out message

addOutMsg : outMsg -> ( model, Platform.Cmd.Cmd msg ) -> ( model, outMsg, Platform.Cmd.Cmd msg )

Adds an out message to the usual (model, Cmd msg) structure.

andThen : (outMsg -> model -> ( model, outMsg, Platform.Cmd.Cmd msg )) -> ( model, outMsg, Platform.Cmd.Cmd msg ) -> ( model, outMsg, Platform.Cmd.Cmd msg )

Allows update functions that also produce lists of out messages, to be chained together. The Cmds will be batched together, but out messages will not.

andMap : (outMsg -> model -> ( model2, outMsg2, Platform.Cmd.Cmd msg )) -> ( model, outMsg, Platform.Cmd.Cmd msg ) -> ( model2, outMsg2, Platform.Cmd.Cmd msg )

Allows update functions that also produce lists of out messages, to be chained together, whilst also transforming the model and outMsg type. The Cmds will be batched together, but out messages will not.

toUpdate3Alt : (msg -> model -> ( model, Platform.Cmd.Cmd msg, outMsg )) -> msg -> model -> ( model, outMsg, Platform.Cmd.Cmd msg )

Swaps the order of the return arguments to the alternative order used by this module.