Convenience functions for working with updates in Elm
Allows you to conditionally trigger updates based on a predicate. Can be used with the pipeline operator.
For example:
update msg model =
case msg of
SomeMessage i ->
( model, Cmd.none )
|> filter (i > 10)
(andThen update BiggerThanTen
>> andThen update AnotherMessage
>> andThen update EvenMoreMessages
)
|> andThen (update AlwaysTriggeredAfterPredicate)If you want use to the pipeline operator in the nested pipeline, consider a lambda:
|> filter (i > 10)
( \state -> state
|> andThen update BiggerThanTen
|> andThen update AnotherMessage
|> andThen update EvenMoreMessages
)
|> andThen (update AlwaysTriggeredAfterPredicate)Allows you to update the model in an update pipeline.
For example
update msg model = model ! []
|> updateModel \model -> { model | a = 1 }
|> updateModel \model -> { model | b = 2 }Allows you to attach a Cmd to an update pipeline.
For example:
update msg model =
( model, Cmd.none )
|> andThen update AMessage
|> addCmd doSomethingWithASideEffectMap over the Cmd in an update pipeline
Allows you to attach multiple messages to an update at once.
For example:
update msg model =
( model, Cmd.none )
|> sequence update
[ AMessage
, AnotherMessage
, AThirdMessage
]
Allows update call composition. Can be used with the pipeline operator (|>) to chain updates.
For example: