jamesrweb/elm-cqrs/3.0.0

NOTE: the latest version is 5.0.3

Cqrs.Command

Types

{ 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

type alias Response =
CommandResponse CommandError ()

Represents the response state of a command.

Represents the possible states of a command.

type alias CommandError =
String

Represents the default inner data type of a Failed variant.

Actions

String
-> Maybe (Error -> CommandError)
-> Value
-> (Response -> msg)
-> Cmd msg

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

StandardRequestConfig
-> String
-> Maybe (Error -> CommandError)
-> Value
-> (Response -> msg)
-> Cmd msg

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

requestTask : String -> Maybe (Error -> CommandError) -> Value -> Task () Response

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

TaskRequestConfig
-> String
-> Maybe (Error -> CommandError)
-> Value
-> Task () Response

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

Constructors

succeed : Response

Constructs the Succeeded variant of a Cqrs.Command.Response.

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.Response.

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

Helpers

map : (a -> b) -> CommandResponse e a -> CommandResponse e b

Maps the Succeeded variant of a given Cqrs.Command.Response

mapError : (e -> f) -> CommandResponse e a -> CommandResponse f a

Maps the Failed variant of a given Cqrs.Command.Response.

withDefault : e -> CommandResponse e () -> e

Provides a default case for a Cqrs.Command.Response where the Succeeded variant is in the default () state.

Unwraps a homogeneous Cqrs.Command.Response to its' inner value from the given variant.

Checks if a given Cqrs.Command.Response is a Succeeded variant.

succeeded Succeeded --> True


succeeded (Failed "reason") --> False
failed : CommandResponse e a -> Bool

Checks if a given Cqrs.Command.Response is a Failed variant.

failed Succeeded --> False


failed (Failed "reason") --> True
reason : CommandResponse e a -> Maybe e

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

reason Succeeded --> Nothing


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

Codecs

decoder : Decoder Response

Decodes a given payload into a Cqrs.Command.Response.