@gernsdorfer/ngrx-lite
Version: 
[]() [](https://github.com/gernsdorfer/ngrx-lite/action
182 lines (168 loc) • 7.91 kB
TypeScript
import * as i0 from '@angular/core';
import { InjectionToken, Injectable, OnDestroy, Type } from '@angular/core';
import * as _ngrx_store from '@ngrx/store';
import { Store, Action, ActionCreator } from '@ngrx/store';
import { FormGroup } from '@angular/forms';
import * as rxjs from 'rxjs';
import { Subject, Observable } from 'rxjs';
import { ComponentStore as ComponentStore$1 } from '@ngrx/component-store';
import { Actions } from '@ngrx/effects';
declare enum EffectStates {
    ERROR = "ERROR",
    LOAD = "LOAD",
    SUCCESS = "SUCCESS"
}
interface ClientStoragePlugin {
    getDefaultState: <STATE>(storeName: string) => STATE | undefined;
    setStateToStorage: <STATE>(storeName: string, data: STATE) => void;
}
type LoadingStoreState<ITEM, ERROR> = {
    isLoading: boolean;
    error?: ERROR;
    item?: ITEM;
};
declare const SessionStoragePlugin: InjectionToken<ClientStoragePlugin>;
declare const LocalStoragePlugin: InjectionToken<ClientStoragePlugin>;
declare class ClientStorage implements ClientStoragePlugin {
    private store?;
    constructor(store?: Storage | undefined);
    getDefaultState<STATE>(storeName: string): STATE | undefined;
    setStateToStorage<STATE>(storeName: string, state: STATE): void;
}
declare const sessionStoragePlugin: ClientStorage;
declare const localStoragePlugin: ClientStorage;
declare class RouterStoreModule {
    static ɵfac: i0.ɵɵFactoryDeclaration<RouterStoreModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<RouterStoreModule, never, never, never>;
    static ɵinj: i0.ɵɵInjectorDeclaration<RouterStoreModule>;
}
declare const getEffectAction: <ARGS extends string = never, P extends LoadingStoreState<unknown, unknown> = LoadingStoreState<unknown, unknown>>({ storeName, effectName, dynamicStoreName, type, }: {
    storeName: string;
    dynamicStoreName?: ARGS;
    effectName: string;
    type: EffectStates;
}) => _ngrx_store.ActionCreator<string, (props: {
    payload: P;
}) => {
    payload: P;
} & _ngrx_store.Action<string>>;
declare const getCustomActionWithDynamicStore: <ARGS extends string = never, P extends object = object>({ storeName, dynamicStoreName, actionName, }: {
    storeName: string;
    dynamicStoreName?: ARGS;
    actionName?: string;
}) => _ngrx_store.ActionCreator<string, (props: {
    payload: P;
}) => {
    payload: P;
} & _ngrx_store.Action<string>>;
declare const getCustomAction: <P extends object>({ storeName, dynamicStoreName, actionName, }: {
    storeName: string;
    dynamicStoreName?: string;
    actionName?: string;
}) => _ngrx_store.ActionCreator<string, (props: {
    payload: P;
}) => {
    payload: P;
} & _ngrx_store.Action<string>>;
declare class DynamicStore<T extends string = string> {
    dynamicStoryName?: T;
}
type GLOBAL_STORE = Injectable & {
    providedIn: 'root' | 'platform';
};
type StoreType<STORE extends Injectable> = STORE extends GLOBAL_STORE ? DynamicStore<never> : OnDestroy & DynamicStore;
declare class CreateStoreAsFn<INJECTION extends Injectable, STORE extends StoreType<INJECTION>> {
    private store;
    private injectionOptions?;
    constructor(store: Type<STORE>, injectionOptions?: INJECTION | undefined);
    inject(dynamicStoreName?: INJECTION extends {
        providedIn: 'root' | 'platform' | 'any';
    } ? never : STORE['dynamicStoryName']): STORE;
    private loadFromRoot;
    private createNewStoreInstance;
    private storeNotFoundHandling;
}
declare const createStoreAsFn: <INJECTION extends Injectable, STORE extends INJECTION extends GLOBAL_STORE ? object : OnDestroy & DynamicStore>(store: Type<STORE>, injectionOptions?: INJECTION) => CreateStoreAsFn<INJECTION, STORE>;
declare class DevToolHelper {
    private _isTimeTravelActive;
    setTimeTravelActive(isTimeTravelActive: boolean): void;
    isTimeTravelActive(): boolean;
    static ɵfac: i0.ɵɵFactoryDeclaration<DevToolHelper, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<DevToolHelper>;
}
declare class ComponentStore<STATE extends object> extends ComponentStore$1<STATE> implements OnDestroy {
    protected actions: Actions<any>;
    protected ngrxStore: Store<any>;
    protected devToolHelper: DevToolHelper;
    protected skipLogForStore: boolean;
    protected storeName: string;
    constructor(state: STATE);
    subject: Subject<void>;
    ngOnDestroy(): void;
    createEffect<V = Action>(effect: (action: Actions) => Observable<V>): Observable<V>;
    onActions(actions: ActionCreator[]): (callback: () => unknown) => void;
    setState(stateOrUpdaterFn: ((state: STATE) => STATE) | STATE, action?: string, { skipLog, forced, }?: {
        skipLog?: boolean;
        forced?: boolean;
    }): void;
    patchState(partialStateOrUpdaterFn: Partial<STATE> | ((state: STATE) => Partial<STATE>), action?: string): void;
    protected dispatchCustomAction(action: string, state: STATE): void;
    static ɵfac: i0.ɵɵFactoryDeclaration<ComponentStore<any>, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<ComponentStore<any>>;
}
declare const getDefaultComponentLoadingState: <ITEM, ERROR>(state?: Partial<LoadingStoreState<ITEM, ERROR>>) => LoadingStoreState<ITEM, ERROR>;
declare class ComponentLoadingStore<ITEM, ERROR> extends ComponentStore<LoadingStoreState<ITEM, ERROR>> {
    constructor(state: LoadingStoreState<ITEM, ERROR>);
    private hasPendingEffect;
    loadingEffect: <EFFECT_PARAMS = void>(name: string, effect: (params: EFFECT_PARAMS) => Observable<LoadingStoreState<ITEM, ERROR>["item"]>, { canCache, skipSameActions, skipSamePendingActions, repeatActions, }?: {
        /**
         * @deprecated Please use skipSamePendingActions instead
         */
        canCache?: boolean;
        skipSamePendingActions?: boolean;
        skipSameActions?: boolean;
        repeatActions?: ActionCreator[];
    }) => void | EFFECT_PARAMS extends void ? (observableOrValue?: EFFECT_PARAMS | Observable<EFFECT_PARAMS> | undefined) => rxjs.Subscription : (observableOrValue: EFFECT_PARAMS | Observable<EFFECT_PARAMS>) => rxjs.Subscription;
    private getSkipSamePendingActions;
    private checkEffectPayload;
    private runEffect;
    private finishEffect;
    static ɵfac: i0.ɵɵFactoryDeclaration<ComponentLoadingStore<any, any>, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<ComponentLoadingStore<any, any>>;
}
type StoragePluginTypes = 'sessionStoragePlugin' | 'localStoragePlugin';
declare class StoreFactory {
    private store;
    constructor();
    createComponentStore<STATE extends object>({ storeName, plugins, defaultState, skipLog, }: {
        defaultState: STATE;
        plugins?: {
            storage?: StoragePluginTypes;
        };
        skipLog?: boolean;
        storeName: string;
    }): ComponentStore<STATE>;
    createFormComponentStore<FORM_STATE extends object>({ storeName, plugins, formGroup, skipLog, }: {
        formGroup: FormGroup;
        storeName: string;
        plugins?: {
            storage?: StoragePluginTypes;
        };
        skipLog?: boolean;
    }): ComponentStore<FORM_STATE>;
    createComponentLoadingStore<ITEM, ERROR>({ defaultState, plugins, skipLog, storeName, }: {
        defaultState?: {
            item?: ITEM;
            error?: ERROR;
        };
        plugins?: {
            storage?: StoragePluginTypes;
        };
        skipLog?: boolean;
        storeName: string;
    }): ComponentLoadingStore<ITEM, ERROR>;
    static ɵfac: i0.ɵɵFactoryDeclaration<StoreFactory, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<StoreFactory>;
}
export { ComponentLoadingStore, ComponentStore, CreateStoreAsFn, DynamicStore, EffectStates, LocalStoragePlugin, RouterStoreModule, SessionStoragePlugin, StoreFactory, createStoreAsFn, getCustomAction, getCustomActionWithDynamicStore, getDefaultComponentLoadingState, getEffectAction, localStoragePlugin, sessionStoragePlugin };
export type { ClientStoragePlugin, LoadingStoreState };