ngrx-loading-state
Version:
NgRx Loading State consistently manages loading actions such as API fetches.
60 lines (59 loc) • 2.97 kB
TypeScript
import { DefaultProjectorFn, MemoizedSelector } from '@ngrx/store';
import { NoIntersection } from '../utils';
import { LoadingActions } from './loading-state-actions';
import { FailureAction, LoadAction, LoadingStates, WithLoadingStatesOnly } from './loading-state-types';
export declare function load<LoadPayloadType extends NotLoadingAction<LoadPayloadType>>(): Load<LoadPayloadType>;
export declare function success<SuccessPayloadType>(): Success<SuccessPayloadType>;
export declare function failure<FailurePayloadType extends NotFailureAction<FailurePayloadType>>(): Failure<FailurePayloadType>;
/**
* Creates a set of load, success, failure actions. Selectors and reducers are always bundled into
* the same structure.
*
* @param type The "type" of the action.
* @param _load See usage example
* @param _success See usage example
* @param _failure See usage example
* @returns An instance of LoadingActions class that bundles together actions, selectors and reducers.
* @example
* export const fetchItem = createLoadingActions(
* 'Fetch Item',
* load<{ itemId: number }>(), // Action type is: 'Fetch Item'
* success<{ item: object }>(), // Action type is: 'Fetch Item Success'
* failure<{}>() // Action type is: 'Fetch Item Failure'
* );
*/
export declare function createLoadingActions<LoadPayloadType extends object, SuccessPayloadType extends object, FailurePayloadType extends object>(type: string, _load: Load<LoadPayloadType>, _success: Success<SuccessPayloadType>, _failure: Failure<FailurePayloadType>): LoadingActions<LoadPayloadType, SuccessPayloadType, FailurePayloadType>;
/**
*
* @param featureSelector Selector that selects the current feature slice of the store.
* @returns Selector that selects the loadingStates field from the store
* @example
* // Using ngrx's createFeatureSelector to select the feature slice from global store.
* const selectState = createFeatureSelector<SimpleState>(SIMPLE_FEATURE_KEY);
* const selectLoadingStates = createLoadingStatesSelector(selectState);
*
* You can then use selectLoadingStates to compose other selectors. eg.
*
* export const fetchItem = createLoadingActions(
* 'Fetch Item',
* load<{ itemId: number }>(),
* success<{ item: object }>(),
* failure<{}>()
* );
*
* export const fetchItemSelectors = fetchItem.createSelectors(selectLoadingStates);
*
*/
export declare function createLoadingStatesSelector<State extends WithLoadingStatesOnly>(featureSelector: MemoizedSelector<object, State, DefaultProjectorFn<State>>): MemoizedSelector<object, LoadingStates, DefaultProjectorFn<LoadingStates>>;
declare class Load<_LoadPayloadType> {
type: 'LOAD';
}
declare class Success<_SuccessPayloadType> {
type: 'SUCCESS';
}
declare class Failure<_FailurePayloadType> {
type: 'FAILURE';
}
declare type NotLoadingAction<T> = NoIntersection<T, LoadAction>;
declare type NotFailureAction<T> = NoIntersection<T, FailureAction>;
export {};