ccapndave/elm-update-extra/2.0.0

NOTE: this package is not compatible with Elm 0.19.1

Update.Extra

Convenience functions for working with updates in Elm

(msg -> model -> ( model, Cmd msg ))
-> msg
-> ( model, Cmd msg )
-> ( model, Cmd msg )

Allows update call composition. Can be used with the pipeline operator (|>) to chain updates.

For example:

update msg model =
  model ! []
    |> andThen update SomeMessage
    |> andThen update SomeOtherMessage
    |> andThen update (MessageWithArguments "Hello")
    ...

The same can be achieved using Update.Extra.Infix.(:>).

For example:

import Update.Extra.Infix exposing ((:>))


update msg model =
  model ! []
    :> update SomeMessage
    :> update SomeOtherMessage
    :> update (MessageWithArguments "Hello")
Bool
-> (( model, Cmd msg ) -> ( model, Cmd msg ))
-> ( model, Cmd msg )
-> ( model, Cmd msg )

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 ! []
        |> 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)
addCmd : Cmd msg -> ( model, Cmd msg ) -> ( model, Cmd msg )

Allows you to attach a Cmd to an update pipeline.

For example:

update msg model = model ! []
  |> andThen update AMessage
  |> addCmd doSomethingWithASideEffect
(msg -> model -> ( model, Cmd msg ))
-> List msg
-> ( model, Cmd msg )
-> ( model, Cmd msg )

Allows you to attach multiple messages to an update at once.

For example:

update msg model = model ! []
  |> sequence update
    [ AMessage
    , AnotherMessage
    , AThirdMessage
    ]