Update function helpers
Wraps a command and a model in a PrimaUpdate pair
model
|> withCmd cmd
-- => (model, cmd)Concatenates Updates batching their updates
(someModel, someCommand)
|> andThen (\ someModel -> (anotherModel, anotherCommand))
-- => (anotherModel, Cmd.batch [someCommand, anotherCommand] )Like withCmd but batches them
model
|> withCmds [cmd1, cmd2]
-- => (model, Cmd.batch [cmd1, cmd2])Used to apply an updated model to the cmds in fluid style updating
serializeUsers : Model -> Cmd Msg
logEvent : String -> Model -> Cmd Msg
update : Msg -> Model -> PrimaUpdate Model Msg
update msg model =
case msg of
FetchedUsers newUsers ->
model
|> setUsers newUsers
|> withCmdsMap [ serializeUsers, logEvent "got users" ]Lifts a model to a (model, Cmd msg) pair
Maps the model preserving the current cmds
{ count = 0 }
|> PrimaCmd.withoutCmds
|> PrimaCmd.mapModel (updateCount ((+) 1))
|> Expect.equal ({ count = 1 }, Cmd.none)Cmd.maps the pair cmd, preserving the model
intCmd : Cmd Int
intCmd =
Task.succeed 42 |> Task.perform identity
pair : Update () String
pair =
()
|> withCmd intCmd
|> mapCmd String.fromInt
The alias for a
(Model, Cmd Msg)pair.