jamesrweb/elm-cqrs/1.0.1

NOTE: the latest version is 5.0.3

Cqrs.Query

Types

type Response a

Represents the possible response 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.

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.

Constructors

succeed : a -> Response a

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 : String -> Response 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) -> Response a -> Response b

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

mapError : (String -> String) -> Response a -> Response a

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

succeeded : Response a -> Bool

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

succeeded (Data []) --> True


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

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

failed (Data []) --> False


failed (Error "reason") --> True
data : Response 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 : Response a -> Maybe String

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.