ngx-http-request-state
Version:
Angular library for wrapping HttpClient responses with loading & error information to allow observing load/loading/error state changes as a stream of events.
17 lines (16 loc) • 1.13 kB
TypeScript
import { HttpRequestState, LoadedState, ErrorState } from './model';
/**
* Given an array of HttpRequestState<T>, merge them together into a new single HttpRequestState<T>,
* based on a supplied merging strategy of values (mergeValues) or of errors (mergeErrors).
*
* One can think of this function as allowing one to act "inside" the states, directly on the values or errors.
*
* Use this with combineLatest, instead of forkJoin, to get loading updates.
*
* @param states Array of states of the same type that should be merged together.
* @param mergeValues Handles how to merge values together when all states have loaded.
* @param mergeErrors Handles how to merge errors together in case one or more of the states end up in ErrorState.
* If not specified, the first error is simply used as the error of the merged state
* @returns The merged HttpRequestState<T>
*/
export declare function mergeStates<T>(states: HttpRequestState<T>[], mergeValues: (states: LoadedState<T>['value'][]) => LoadedState<T>['value'], mergeErrors?: (states: ErrorState<T>['error'][]) => ErrorState<T>['error']): HttpRequestState<T>;