A datatype representing fetched data in five different states.
Based on Kris's RemoteData.
For the same motivations that are presented in Kris' version,
with the small addition of always using transport and custom errors,
and aliasing GraphqlError instead of Http.Error.
While RemoteData can model any type of errors,
the most common one Paack has encountered is when fetching data from a Graphql query,
and getting back a GraphqlError.
Because of that, GraphqlHttpData is provided as a useful alias.
Based on Kris's WebData.
Convert a Response, probably produced from a query result, to a RemoteData value.
Based on Kris's fromResult.
True when Success _.
NOTE: This function opposes the purpose of this package by eliminating not aimed states. Always evaluate using a switch-case instead.
True when Failure _.
NOTE: This function opposes the purpose of this package by eliminating not aimed states. Always evaluate using a switch-case instead.
True when Failure (isCustomError _).
NOTE: This function opposes the purpose of this package by eliminating not aimed states. Always evaluate using a switch-case instead.
True when Failure (Transport _).
NOTE: This function opposes the purpose of this package by eliminating not aimed states. Always evaluate using a switch-case instead.
True when Loading _.
NOTE: This function opposes the purpose of this package by eliminating not aimed states. Always evaluate using a switch-case instead.
True when NotAsked.
NOTE: This function opposes the purpose of this package by eliminating not aimed states. Always evaluate using a switch-case instead.
Transforms Failure error into Just error, and anything else into Nothing.
NOTE: This function opposes the purpose of this package by eliminating not aimed states. Always evaluate using a switch-case instead.
Apply a function to a RemoteData.Success. If the data is Success, it will be converted.
If the data is anything else, the same value will propagate through.
Transform a Failure (Custom a) value. If the data is Failure (Custom a), it will be converted.
If the data is anything else, the same value will propagate through.
Transform a Failure (Transport a) value. If the data is Failure (Transport a), it will be converted.
If the data is anything else, the same value will propagate through.
Transform a Failure value. If the data is Failure, it will be converted.
If the data is anything else, the same value will propagate through.
If the data is Success return its value,
but if the data is anything else then return a given default alternative.
NOTE: This function opposes the purpose of this package by eliminating not aimed states. Always evaluate using a switch-case instead.
For doing pipes instead of switch-case.
someData
|> RemoteData.map (always "Success")
|> RemoteData.mapCustomError (always "Expected failure")
|> RemoteData.mapTransportError (always "Network error")
|> RemoteData.merge "Loading or never asked"
Frequently when you're fetching data from an API, you want to represent five different states:
NotAsked- We haven't asked for the data yet.Loading- We've asked, but haven't got an answer yet.Failure (Custom error)- We asked, but we received one of the custom-defined errors instead. Here's the error.Failure (Transport error)- We asked, but something went wrong on the network-side. Here's the error.Success data- Everything worked, and here's the data.Based on Kris's
RemoteData.