RemoteData
RemoteData:
object
Defined in: Core/RemoteData.ts:30
Type Declaration
Section titled “Type Declaration”ap: <
E,A>(arg) => <B>(data) =>RemoteData<E,B>
Applies a function wrapped in a RemoteData to a value wrapped in a RemoteData.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”RemoteData<E, A>
Returns
Section titled “Returns”<B>(data) => RemoteData<E, B>
Example
Section titled “Example”chain: <
E2,A,B>(f) => <E1>(data) =>RemoteData<E2|E1,B>
Chains RemoteData computations. If the input is Success, passes the value to f. Otherwise, propagates the current state.
Type Parameters
Section titled “Type Parameters”E2
A
B
Parameters
Section titled “Parameters”(a) => RemoteData<E2, B>
Returns
Section titled “Returns”<E1>(data) => RemoteData<E2 | E1, B>
Example
Section titled “Example”filter
Section titled “filter”filter: <
E,A>(pred,onFalse) => (data) =>RemoteData<E,A>
Filters a Success value. When the predicate passes, the value is kept. When it fails,
Success becomes Failure using the error produced by onFalse. All other states pass through unchanged.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”(a) => boolean
onFalse
Section titled “onFalse”(a) => E
Returns
Section titled “Returns”(data) => RemoteData<E, A>
Example
Section titled “Example”fold: <
E,A,B>(onFailure,onNotAsked,onLoading,onSuccess) => (data) =>B
Extracts the value from a RemoteData by providing handlers for all four cases.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”onFailure
Section titled “onFailure”(e) => B
onNotAsked
Section titled “onNotAsked”() => B
onLoading
Section titled “onLoading”() => B
onSuccess
Section titled “onSuccess”(a) => B
Returns
Section titled “Returns”(data) => B
Example
Section titled “Example”from:
object
from.Maybe
Section titled “from.Maybe”Maybe: <
E>(onNone) => <A>(data) =>RemoteData<E,A>
Converts a Maybe to a RemoteData. Some becomes Success, None becomes Failure using the onNone error producer.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”onNone
Section titled “onNone”() => E
Returns
Section titled “Returns”<A>(data) => RemoteData<E, A>
Example
Section titled “Example”from.Result
Section titled “from.Result”Result: <
E,A>(data) =>RemoteData<E,A>
Converts a Result to a RemoteData. Ok becomes Success, Err becomes Failure.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”Result<E, A>
Returns
Section titled “Returns”RemoteData<E, A>
Example
Section titled “Example”getOrElse
Section titled “getOrElse”getOrElse: <
B>(defaultValue) => <E,A>(data) =>B|A
Returns the success value or a default value if the RemoteData is not Success.
The default can be a different type, widening the result to A | B.
Type Parameters
Section titled “Type Parameters”B
Parameters
Section titled “Parameters”defaultValue
Section titled “defaultValue”() => B
Returns
Section titled “Returns”<E, A>(data) => B | A
Example
Section titled “Example”is:
object
is.failure
Section titled “is.failure”failure: <
E,A>(data) =>data is Failure<E>=isFailure
Type guard that checks if a RemoteData is Failure.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”RemoteData<E, A>
Returns
Section titled “Returns”data is Failure<E>
Example
Section titled “Example”is.loading
Section titled “is.loading”loading: <
E,A>(data) =>data is Loading=isLoading
Type guard that checks if a RemoteData is Loading.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”RemoteData<E, A>
Returns
Section titled “Returns”data is Loading
Example
Section titled “Example”is.notAsked
Section titled “is.notAsked”notAsked: <
E,A>(data) =>data is NotAsked=isNotAsked
Type guard that checks if a RemoteData is NotAsked.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”RemoteData<E, A>
Returns
Section titled “Returns”data is NotAsked
Example
Section titled “Example”is.success
Section titled “is.success”success: <
E,A>(data) =>data is Success<A>=isSuccess
Type guard that checks if a RemoteData is Success.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”RemoteData<E, A>
Returns
Section titled “Returns”data is Success<A>
Example
Section titled “Example”make:
object
make.failure
Section titled “make.failure”failure: <
E>(error) =>Failure<E> =makeFailure
Creates a Failure RemoteData with the given error.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”Failure<E>
Example
Section titled “Example”make.loading
Section titled “make.loading”loading: () =>
Loading=makeLoading
Creates a Loading RemoteData.
Returns
Section titled “Returns”Example
Section titled “Example”make.notAsked
Section titled “make.notAsked”notAsked: () =>
NotAsked=makeNotAsked
Creates a NotAsked RemoteData.
Returns
Section titled “Returns”Example
Section titled “Example”make.success
Section titled “make.success”success: <
A>(value) =>Success<A> =makeSuccess
Creates a Success RemoteData with the given value.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”Success<A>
Example
Section titled “Example”map: <
A,B>(f) => <E>(data) =>RemoteData<E,B>
Transforms the success value inside a RemoteData.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => B
Returns
Section titled “Returns”<E>(data) => RemoteData<E, B>
Example
Section titled “Example”mapError
Section titled “mapError”mapError: <
E,F>(f) => <A>(data) =>RemoteData<F,A>
Transforms the error value inside a RemoteData.
Type Parameters
Section titled “Type Parameters”E
F
Parameters
Section titled “Parameters”(e) => F
Returns
Section titled “Returns”<A>(data) => RemoteData<F, A>
Example
Section titled “Example”match: <
E,A,B>(cases) => (data) =>B
Pattern matches on a RemoteData, returning the result of the matching case.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”failure
Section titled “failure”(e) => B
loading
Section titled “loading”() => B
notAsked
Section titled “notAsked”() => B
success
Section titled “success”(a) => B
Returns
Section titled “Returns”(data) => B
Example
Section titled “Example”recover
Section titled “recover”recover: <
E,B>(fallback) => <A>(data) =>RemoteData<E,B|A>
Recovers from a Failure state by providing a fallback RemoteData.
The fallback can produce a different success type, widening the result to RemoteData<E, A | B>.
Type Parameters
Section titled “Type Parameters”E
B
Parameters
Section titled “Parameters”fallback
Section titled “fallback”(e) => RemoteData<E, B>
Returns
Section titled “Returns”<A>(data) => RemoteData<E, B | A>
tap: <
E,A>(f) => (data) =>RemoteData<E,A>
Executes a side effect on the success value without changing the RemoteData.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”(a) => void
Returns
Section titled “Returns”(data) => RemoteData<E, A>
Example
Section titled “Example”tapError
Section titled “tapError”tapError: <
E,A>(f) => (data) =>RemoteData<E,A>
Executes a side effect on the failure error without changing the RemoteData. Useful for logging errors.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”(e) => void
Returns
Section titled “Returns”(data) => RemoteData<E, A>
Example
Section titled “Example”to:
object
to.Maybe
Section titled “to.Maybe”Maybe: <
E,A>(data) =>Maybe<A>
Converts a RemoteData to a Maybe. Success becomes Some, all other states become None.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”RemoteData<E, A>
Returns
Section titled “Returns”Maybe<A>
to.Result
Section titled “to.Result”Result: <
E>(onNotReady) => <A>(data) =>Result<E,A>
Converts a RemoteData to a Result. Success becomes Ok, Failure becomes Err. NotAsked and Loading become Err with the provided fallback error.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”onNotReady
Section titled “onNotReady”() => E
Returns
Section titled “Returns”<A>(data) => Result<E, A>