UNPKG

@versatiledatakit/shared

Version:

Versatile Data Kit Shared library enables reusability of shared features like: NgRx Redux, Error Handlers, Utils, Generic Components, etc.

301 lines (300 loc) • 8.3 kB
import { Copy, ErrorRecord, ErrorStore, Literal, LiteralApiPredicates, LiteralRequestPage, RequestFilter, RequestFilterImpl, RequestOrder, RequestOrderImpl, RequestPage, RequestPageImpl } from '../../../../common'; import { StatusType } from './component-status.model'; /** * ** Literal Component State in purest format ready for Store persisting. */ export interface LiteralComponentState { /** * ** Identifier for Component State. */ readonly id: string; /** * ** Status for Component State. */ readonly status: StatusType; /** * ** Component State Data. * <p> * - Free format Literal Object. * </p> */ readonly data?: { [key: string]: any; }; /** * ** Route path for current State. */ readonly routePath?: string; /** * ** Route path segments for current State. */ readonly routePathSegments?: string[]; /** * ** Search query for Http requests. */ readonly search?: string; /** * ** Page for Http requests. */ readonly page?: LiteralRequestPage; /** * ** Order for Http requests. */ readonly order?: LiteralApiPredicates; /** * ** Filter for Http requests. */ readonly filter?: LiteralApiPredicates; /** * ** Order for Http requests. */ readonly requestParams?: { [key: string]: any; }; /** * ** Task is property that give bi-directional refinement context. * * - Gives context to Effect through Action. * - Gives context to Component through ComponentState (ComponentModel). */ readonly task?: string; /** * ** Router NavigationId bound to this Component State. */ readonly navigationId?: number; /** * ** Error store for ErrorRecords that happen in stream manipulation down to the Components. * <p> * - Ideal for storing Http errors and other runtime errors, so Component could easily leverage that knowledge and show info for User. * </p> */ readonly errors?: ErrorRecord[]; /** * ** Component State UiState, that holds all information for UiElements. * <p> * - Free format Literal Object where key identifier could be (Component/Html Element) name/id/class etc... * </p> */ readonly uiState?: { [key: string]: any; }; } export interface ComponentState extends Literal<LiteralComponentState>, Copy<ComponentState> { /** * ** Identifier for Component State. */ readonly id: string; /** * ** Status for Component State. */ readonly status: StatusType; /** * ** Component State Data. * <p> * - Free format Map. * </p> */ readonly data?: Map<string, any>; /** * ** Route path for current State. */ readonly routePath?: string; /** * ** Route Path Segments for current State. */ readonly routePathSegments?: string[]; /** * ** Search query for Http requests. */ readonly search?: string; /** * ** Page for Http requests. */ readonly page?: RequestPage; /** * ** Order for Http requests. */ readonly order?: RequestOrder; /** * ** Filter for Http requests. */ readonly filter?: RequestFilter; /** * ** Map with different parameters for Http requests. */ readonly requestParams?: Map<string, any>; /** * ** Task is property that give bi-directional refinement context. * * - Gives context to Effect through Action. * - Gives context to Component through ComponentState (ComponentModel). */ readonly task?: string; /** * ** Router NavigationId bound to this Component State. */ readonly navigationId?: number; /** * ** Error store for ErrorRecords that happen in stream manipulation down to the Components. * <p> * - Ideal for storing Http errors and other runtime errors, so Component could easily leverage that knowledge and show info for User. * </p> */ readonly errors?: ErrorStore; /** * ** Component State UiState, that holds all information for UiElements. * <p> * - Free format Map where key identifier could be (Component/Html Element) name/id/class etc... * </p> */ readonly uiState?: Map<string, any>; /** * @inheritDoc */ toLiteral(): LiteralComponentState; /** * @inheritDoc */ toLiteralCloneDeep(): LiteralComponentState; /** * @inheritDoc */ copy(state?: Partial<ComponentState>): ComponentState; } /** * ** ComponentState implementation will all methods and other utilities. */ export declare class ComponentStateImpl implements ComponentState { /** * @inheritDoc */ readonly id: string; /** * @inheritDoc */ readonly status: StatusType; /** * @inheritDoc */ readonly data: Map<string, any>; /** * @inheritDoc */ readonly routePath: string; /** * @inheritDoc */ readonly routePathSegments: string[]; /** * @inheritDoc */ readonly search: string; /** * @inheritDoc */ readonly page: RequestPageImpl; /** * @inheritDoc */ readonly order: RequestOrderImpl; /** * @inheritDoc */ readonly filter: RequestFilterImpl; /** * @inheritDoc */ readonly requestParams: Map<string, any>; /** * @inheritDoc */ readonly task: string; /** * @inheritDoc */ readonly navigationId: number; /** * @inheritDoc */ readonly errors: ErrorStore; /** * @inheritDoc */ readonly uiState: Map<string, any>; /** * ** Constructor. * * <p><b> * Important: * </b></p> * <p> * If you add new Property in {@link LiteralComponentState}/{@link ComponentState} * <ul> * <li> * Implement field in {@link ComponentStateImpl} and handle null/undefined, assign defaults (required for Collections). * </li> * <li> * Copy/Clone process have to be handled manually (for performance gain) in methods: * * {@link ComponentStateImpl.fromLiteralComponentState} * {@link ComponentStateImpl.cloneDeepLiteral} * {@link ComponentStateImpl.toLiteral} * </li> * </ul> * </p> */ constructor(stateModelProp: Partial<ComponentState>); /** * ** Factory method. */ static of(stateModel: Partial<ComponentState>): ComponentStateImpl; /** * ** Convert provided {@link LiteralComponentState} into instance of {@link ComponentStateImpl}. * <p> * Every literals could be transformed to their original Collection format. * <ul> * <li> * Object literals could be transformed to Map/WeakMap/Set depends of the needs. * </li> * <li> * Array is keep as it is. * </li> * </ul> * </p> * * @see CollectionsUtil.transformObjectToMap * @see CollectionsUtil.transformMapToObject */ static fromLiteralComponentState(literalStateModel: LiteralComponentState): ComponentStateImpl; /** * ** Make deep clone from Literal Component State. */ static cloneDeepLiteral(literalStateModel: LiteralComponentState): LiteralComponentState; /** * <p> * Every Collection should be transformed to format of JSON supported literals, ready for LocalStorage/SessionStorage persist. * <ul> * <li> * Map/WeakMap/Set have to be transform to Object literal. * </li> * <li> * Array is keep as it is. * </li> * </ul> * </p> * * @see CollectionsUtil.transformObjectToMap * @see CollectionsUtil.transformMapToObject * * @inheritDoc */ toLiteral(): LiteralComponentState; /** * @inheritDoc */ toLiteralCloneDeep(): LiteralComponentState; /** * @inheritDoc */ copy(state?: Partial<ComponentState>): ComponentStateImpl; }