avh4/elm-testable/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Testable.Effects

Testable.Effects is a replacement for the core Effects module. You can use it to create components that can be tested with Testable.TestContext. You can convert Testable.Effects into a core Effects with the Testable module.

Basic Effects

type alias Effects action =
Effects action

Represents some kind of effect. Right now this library supports tasks for arbitrary effects and clock ticks for animations.

none : Effects never

The simplest effect of them all: don’t do anything! This is useful when some branches of your update function request effects and others do not.

Example 5 in elm-architecture-tutorial has a nice example of this with further explanation in the tutorial itself.

task : Task Never a -> Effects a

Turn a Task into an Effects that results in an a value.

Normally a Task has a error type and a success type. In this case the error type is Never meaning that you must provide a task that never fails. Lots of tasks can fail (like HTTP requests), so you will want to use Task.toMaybe and Task.toResult to move potential errors into the success type so they can be handled explicitly.

Example 5 in elm-architecture-tutorial has a nice example of this with further explanation in the tutorial itself.

Combining Effects

map : (a -> b) -> Effects a -> Effects b

Transform the return type of a bunch of Effects. This is primarily useful for adding tags to route Actions to the right place in The Elm Architecture.

Example 6 in elm-architecture-tutorial has a nice example of this with further explanation in the tutorial itself.

batch : List (Effects action) -> Effects action

Create a batch of effects. The following example requests two tasks: one for the user’s picture and one for their age. You could put a bunch more stuff in that batch if you wanted!

init : String -> (Model, Effects Action)
init userID =
    ( { id = userID
      , picture = Nothing
      , age = Nothing
      }
    , batch [ getPicture userID, getAge userID ]
    )


-- getPicture : String -> Effects Action
-- getAge : String -> Effects Action

Example 6 in elm-architecture-tutorial has a nice example of this with further explanation in the tutorial itself.

Running Effects

type alias Never =
Never

A type that is "uninhabited". There are no values of type Never, so if something has this type, it is a guarantee that it can never happen. It is useful for demanding that a Task can never fail.