imng-ngrx-utils
Version:
This library was generated with [Nx](https://nx.dev).
107 lines (92 loc) • 3.72 kB
TypeScript
import * as _ngrx_store from '@ngrx/store';
import { Action, Store, MemoizedSelector } from '@ngrx/store';
import { IdType } from 'imng-nrsrx-client-utils';
import { Subscription, OperatorFunction, Observable } from 'rxjs';
import { OnDestroy } from '@angular/core';
interface Payload<T> {
payload: T;
}
declare function createPayloadAction<T>(actionType: string): _ngrx_store.FunctionWithParametersType<[payload: T], {
payload: T;
} & _ngrx_store.Action<string>> & _ngrx_store.Action<string>;
interface ModalPayload<T> {
modalState: string;
entity: T;
}
declare function createModalAction<T>(actionType: string): _ngrx_store.FunctionWithParametersType<[payload: ModalPayload<T>], {
payload: ModalPayload<T>;
} & _ngrx_store.Action<string>> & _ngrx_store.Action<string>;
declare function isTruthy(value: unknown): boolean;
declare function isFalsy(value: unknown): boolean;
declare function findAndModify<ENTITY extends {
id?: IdType | null;
}>(data: ENTITY[], lookupId: IdType | undefined, modificationLogic: (matchingRecord: ENTITY) => void): ENTITY[];
declare function findAndMerge<ENTITY extends {
id?: IdType;
}, COLLECTION_ENTITY extends {
id?: IdType;
}>(record: ENTITY, data: COLLECTION_ENTITY[]): ENTITY;
/**
* Spreads the objects in the dataset1, with a matching id object from the dataset2.
* @param dataset1 The original dataset, these are the records you can expect to get back.
* @param dataset2 This dataset will be used to augment the individuals records in dataSet1, records will be matched based on 'id'.
* @returns dataset1
*/
declare function matchAndSpread<ENTITY1 extends {
id?: IdType;
}, ENTITY2 extends {
id?: IdType;
}>(dataset1: ENTITY1[], dataset2: ENTITY2[]): ENTITY1[];
declare function removeById<T extends {
id?: IdType;
}>(source: {
data: T[];
total: number;
} | Array<T>, id?: IdType): {
data: T[];
total: number;
} | Array<T> | null;
declare class Subscriptions {
private readonly _subscriptions;
constructor(...items: Subscription[]);
get length(): number;
push(...items: (Subscription | undefined)[]): void;
forEach(callbackfn: (value: Subscription, index: number, array: Subscription[]) => void, thisArg?: unknown): void;
unsubscribeAll(): void;
}
interface Subscribable extends OnDestroy {
allSubscriptions: Subscriptions;
}
declare const imngEffectError: _ngrx_store.FunctionWithParametersType<[payload: {
action: Action;
error: Error;
}], {
payload: {
action: Action;
error: Error;
};
} & Action<string>> & Action<string>;
/**
* Will handle effect error and dispatch an imngEffectError action
* @param action
* @returns
*/
declare function handleEffectError(action: Action): OperatorFunction<Action, Action>;
declare function imngEffectErrorReducer<T extends {
loading: boolean;
error: unknown;
}>(state: T, effectError: {
payload: {
error: Error;
};
}): T;
declare function getById<T extends {
id?: IdType | null;
}>(source: {
data: T[];
total: number;
} | Array<T>, id?: IdType): T | undefined;
declare function sleep(milliSeconds: number): Promise<void>;
declare function useCacheIfExists<T_COLLECTION_TYPE>(store: Store, selector: MemoizedSelector<Record<string, any>, T_COLLECTION_TYPE[] | undefined, (featureState: never) => T_COLLECTION_TYPE[] | undefined>): <T>(source: Observable<T>) => Observable<T>;
export { Subscriptions, createModalAction, createPayloadAction, findAndMerge, findAndModify, getById, handleEffectError, imngEffectError, imngEffectErrorReducer, isFalsy, isTruthy, matchAndSpread, removeById, sleep, useCacheIfExists };
export type { ModalPayload, Payload, Subscribable };