ngrx-loading-state
Version:
NgRx Loading State consistently manages loading actions such as API fetches.
60 lines (59 loc) • 2.63 kB
TypeScript
import { Action } from '@ngrx/store/src/models';
import { ActionFactoryResult, CombinedLoadingState, FailureAction, FailureHandlerState, LoadAction, LoadingState } from './loading-state-types';
/**
* See if a new API fetch should be issued.
*
* @param currentState The current loading state.
* @param action The the LoadAction dispatched by the user.
* @returns True if a new API fetch should be issued.
*/
export declare function shouldIssueFetch(currentState: Readonly<LoadingState>, action: Readonly<LoadAction>): boolean;
/**
* Return the type of error handler that should be used.
*
* @param currentState the current state
* @param action the load action dispatched by the user
* @param issueFetch whether the load action should issue a new API call.
* @returns
*/
export declare function getFailureHandlerState(currentState: Readonly<LoadingState>, action: Readonly<LoadAction>, issueFetch: boolean): FailureHandlerState;
/**
* This function make it easier to define the type of prop<T>. Internal use only.
*
* T extends object meets the condition of props function
*
* ref: https://stackoverflow.com/questions/65888508/how-to-use-generic-type-in-ngrx-createaction-props
*
* @param type String type of the action
* @returns An action creator function
*/
export declare function actionFactory<T extends object>(type: string): ActionFactoryResult<T>;
/**
* Make a clone of any object that implements the LoadingState interface, but copy over only
* those fields that are in the LoadingState interface.
*
* @param src Any object that implements the LoadingState interface
* @returns A copy of src with only fields from LoadingState
*/
export declare function cloneLoadingState(src: LoadingState): LoadingState;
/**
* Combine the currentState and the user dispatched LoadAction into newState.
*
* @param action User dispatched LoadAction
* @param currentState Current store state
* @returns A new state if the state should change, null otherwise.
*/
export declare function getNewLoadState(action: LoadAction & Action, currentState: LoadingState): Readonly<LoadingState> | null;
/**
* @returns Always returns a new success state.
*/
export declare function getNewSuccessState(): Readonly<LoadingState>;
/**
* Returns a new FailureState.
*
* @param action User dispatched FailureAction
* @param currentState Current loading state
* @returns A new loading state.
*/
export declare function getNewFailureState(action: FailureAction & Action, currentState: LoadingState): Readonly<LoadingState>;
export declare function combineLoadingStates(loadingStates: LoadingState[]): CombinedLoadingState;