jamesrweb/elm-cqrs/4.0.1

NOTE: the latest version is 5.0.3

Cqrs.Command

{ headers : List Header
, timeout : Maybe Float
, tracker : Maybe String
, risky : Bool
}

Configuration for requests resulting in a Cmd

type alias TaskRequestConfig =
{ headers : List Header
, timeout : Maybe Float
, risky : Bool
}

Configuration for requests resulting in a Task

Represents the possible states of a command.

HTTP

String
-> (e -> f)
-> f
-> Value
-> Decoder e
-> (CommandResponse f -> msg)
-> Cmd msg

Sends a command to the given URL with the provided body and returns a parsed Cqrs.Command.CommandResponse e in turn.

StandardRequestConfig
-> String
-> (e -> f)
-> f
-> Value
-> Decoder e
-> (CommandResponse f -> msg)
-> Cmd msg

Similar to request but a StandardRequestConfig can be passed in for cases where customisation of the request headers, etc are desired.

String
-> (e -> f)
-> f
-> Value
-> Decoder e
-> Task () (CommandResponse f)

Sends a command to the given URL and returns a Task containing the parsed Cqrs.Command.CommandResponse e. The value contained within the Cqrs.Command.CommandResponse e, will be the value parsed via the provided decoder.

TaskRequestConfig
-> String
-> (e -> f)
-> f
-> Value
-> Decoder e
-> Task () (CommandResponse f)

Similar to requestTask but a TaskRequestConfig can be passed in for cases where customisation of the request headers, etc are desired.

Constructors

Constructs the Succeeded variant of a Cqrs.Command.CommandResponse e.

This is useful for testing how your UI will respond to the happy path, without actually sending a command.

Constructs the Failed variant of a Cqrs.Command.CommandResponse e.

This is useful for testing how your UI will respond to the sad path, without actually sending a command.

fromResult : Result e a -> CommandResponse e

Converts a Result e a to a Cqrs.Command.CommandResponse e

fromRemoteData : (e -> f) -> f -> RemoteData x (CommandResponse e) -> CommandResponse f

Converts a given RemoteData x (CommandResponse e) into a Cqrs.Command.CommandResponse e.

State

reason : CommandResponse e -> Maybe e

If a given Cqrs.Command.CommandResponse e was unsuccessful, the reason for the failure will be returned.

reason Succeeded --> Nothing


reason (Failed "reason") --> Just "reason"

Mappers

Maps the Failed variant of a given Cqrs.Command.CommandResponse e.

unwrap : b -> (() -> b) -> CommandResponse e -> b

Convert a CommandResponse e to an a by applying a function if the CommandResponse e is a Succeeded variant or using the provided default value if it is an Failed variant.

unpack : (e -> b) -> (() -> b) -> CommandResponse e -> b

Convert a CommandResponse e to an a by applying either the first function if the CommandResponse e is an Failed variant or the second function if the CommandResponse e is a Succeeded variant.

partition : List (CommandResponse e) -> ( List (), List e )

Partitions a series of CommandResponse e instances into a tuple of successful and unsuccessful responses.

toResult : CommandResponse e -> Result e ()

Converts a Cqrs.Command.CommandResponse e to a Result e a

toMaybe : CommandResponse e -> Maybe ()

Converts a Cqrs.Command.CommandResponse e to a Maybe a

Helpers

Checks if a given Cqrs.Command.CommandResponse e is a Succeeded variant.

succeeded Succeeded --> True


succeeded (Failed "reason") --> False

Checks if a given Cqrs.Command.CommandResponse e is a Failed variant.

failed Succeeded --> False


failed (Failed "reason") --> True

Codec

decoder : Decoder e -> Decoder (CommandResponse e)

Decodes a given payload into a Cqrs.Command.CommandResponse e.