jamesrweb/elm-cqrs/3.0.0

NOTE: the latest version is 5.0.3

Cqrs.Query

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 a =
QueryResponse QueryError a

Represents the response state of a query.

type alias QueryError =
String

Represents the default inner data type of an Error variant.

type QueryResponse e a

Represents the possible states of a query.

Actions

String
-> Maybe (Error -> String)
-> (Response a -> msg)
-> Decoder a
-> Cmd msg

Sends a query to the given URL and returns a Cmd for the given msg containing the parsed Cqrs.Query.Response a. The value contained within the Cqrs.Query.Response a, will be the value parsed via the provided decoder.

StandardRequestConfig
-> String
-> Maybe (Error -> String)
-> (Response a -> msg)
-> Decoder a
-> 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 -> String) -> Decoder a -> Task () (Response a)

Sends a query to the given URL and returns a Task which will contain the parsed Cqrs.Query.Response a. The value contained within the Cqrs.Query.Response a, will be the value parsed via the provided decoder.

TaskRequestConfig
-> String
-> Maybe (Error -> String)
-> Decoder a
-> Task () (Response a)

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

Constructors

Constructs the Data variant of a Cqrs.Query.Response a.

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

fail : e -> QueryResponse e a

Constructs the Error variant of a Cqrs.Query.Response a.

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

Helpers

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

Maps the Data variant of a given Cqrs.Query.Response a and returns a Cqrs.Query.Response b.

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

Maps the Error variant of a given Cqrs.Query.Response a.

withDefault : a -> QueryResponse e a -> a

Provides a default case for a Cqrs.Query.Response in place of the value held within the Error variant.

succeeded : QueryResponse e a -> Bool

Checks if a given Cqrs.Query.Response is a Data variant.

succeeded (Data []) --> True


succeeded (Error "reason") --> False
failed : QueryResponse e a -> Bool

Checks if a given Cqrs.Query.Response is an Error variant.

failed (Data []) --> False


failed (Error "reason") --> True
data : QueryResponse e a -> Maybe a

If a given Cqrs.Query.Response was successful, the data it contains will be returned.

data (Data []) --> Just []


data (Error "reason") --> Nothing
reason : QueryResponse e a -> Maybe e

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

reason (Data []) --> Nothing


reason (Error "reason") --> Just "reason"

Codecs

decoder : Decoder a -> Decoder (Response a)

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