UNPKG

ngrx-loading-state

Version:

NgRx Loading State consistently manages loading actions such as API fetches.

61 lines (60 loc) 4.23 kB
import { Actions } from '@ngrx/effects'; import { Action, DefaultProjectorFn, MemoizedSelector } from '@ngrx/store'; import { TypedAction } from '@ngrx/store/src/models'; import { catchError, Observable, UnaryFunction } from 'rxjs'; import { ActionFactoryResult, LoadingActionsReducerTypes, OnState } from '../loading-state/loading-state-types'; import { Id, IdFailureAction, IdLoadAction, IdLoadingState, IdLoadingStates, IdSuccessAction, WithIdLoadingStatesOnly } from './id-loading-state-types'; /** * IdLoadingAction is similar to LoadingAction with the difference that it's parameterized on a user provided ID. * */ export declare class IdLoadingActions<LoadPayloadType extends object, SuccessPayloadType extends object, FailurePayloadType extends object> { readonly idLoad: ActionFactoryResult<IdLoadAction & LoadPayloadType>; readonly idSuccess: ActionFactoryResult<IdSuccessAction & SuccessPayloadType>; readonly idFailure: ActionFactoryResult<IdFailureAction & FailurePayloadType>; constructor(options: { idLoad: ActionFactoryResult<IdLoadAction & LoadPayloadType>; idSuccess: ActionFactoryResult<IdSuccessAction & SuccessPayloadType>; idFailure: ActionFactoryResult<IdFailureAction & FailurePayloadType>; }); instanceOfIdLoad(action: Action): action is ReturnType<ActionFactoryResult<IdLoadAction & LoadPayloadType>>; instanceOfIdSuccess(action: Action): action is ReturnType<ActionFactoryResult<IdSuccessAction & SuccessPayloadType>>; instanceOfIdFailure(action: Action): action is ReturnType<ActionFactoryResult<IdFailureAction & FailurePayloadType>>; reducer<State extends WithIdLoadingStatesOnly>(options?: { onLoad?: (state: OnState<State>, action: IdLoadAction & LoadPayloadType & TypedAction<string>) => State; onSuccess?: (state: OnState<State>, action: IdSuccessAction & SuccessPayloadType & TypedAction<string>) => State; onFailure?: (state: OnState<State>, action: IdFailureAction & FailurePayloadType & TypedAction<string>) => State; }): [ LoadingActionsReducerTypes<State>, LoadingActionsReducerTypes<State>, LoadingActionsReducerTypes<State> ]; catchError(id: Id): ReturnType<typeof catchError>; /** * Returns a map of selectors for loading, success, error, and the entire state. * The advantage of doing it in a bundle is that we can share the result of createStateSelector(), * if we separated into individual functions, each function might need to call createStateSelector() * to create a new instance of the selector. We can't cache any created selectors because will cause * memory leak since the cached references are always help in this class and hence does not get released. * @param selectLoadingStates Selector that returns the loadingStats of the feature slice. You can use createLoadingStatesSelector() * to create it. * @returns A collection of selectors * state: the LoadingState * loading: True if loading * success: True if last load was successful * error: LrError2 object if previous loading failed. * */ createIdSelectors(selectIdLoadingStates: MemoizedSelector<object, IdLoadingStates, DefaultProjectorFn<IdLoadingStates>>): { state: (id: Id) => MemoizedSelector<object, IdLoadingState, DefaultProjectorFn<IdLoadingState>>; loading: (id: Id) => MemoizedSelector<object, boolean, DefaultProjectorFn<boolean>>; success: (id: Id) => MemoizedSelector<object, boolean, DefaultProjectorFn<boolean>>; error: (id: Id) => MemoizedSelector<object, any, DefaultProjectorFn<any>>; combinedState: MemoizedSelector<object, any, DefaultProjectorFn<any>>; }; idLoadHandler(fetch: (idActions$: Observable<IdLoadAction & LoadPayloadType & TypedAction<string>>, id: Id) => Observable<Action>): UnaryFunction<Observable<Action>, Observable<Action>>; createEffect(actions$: Actions, fetch: (idActions$: Observable<IdLoadAction & LoadPayloadType & TypedAction<string>>, id: Id) => Observable<Action>): Observable<Action> & import("@ngrx/effects").CreateEffectMetadata; private get key(); private getIdLoadingState; private setState; }