UNPKG

@versatiledatakit/shared

Version:

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

174 lines (173 loc) 7.42 kB
import { OnDestroy, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { ArrayElement } from '../../../../utils'; import { TaurusNavigateAction } from '../../../../common'; import { NavigationService } from '../../../navigation'; import { ComponentModel } from '../../model'; import { ComponentService } from '../../services'; import { TaurusErrorBaseComponent } from '../error-base'; import * as i0 from "@angular/core"; /** * ** Superclass Component for all other Components that want to use NgRx Store and all lifecycle hooks from Taurus. */ export declare abstract class TaurusBaseComponent extends TaurusErrorBaseComponent implements OnInit, OnDestroy { protected readonly componentService: ComponentService; protected readonly navigationService: NavigationService; protected readonly activatedRoute: ActivatedRoute; /** * @inheritDoc */ static readonly CLASS_NAME: string; /** * @inheritDoc */ static readonly PUBLIC_NAME: string; private static _routeStateFactory; /** * ** Field that hold Component Model. */ model: ComponentModel; /** * ** UUID is identifier for every Subclass in Components state Store. */ abstract readonly uuid: string; /** * ** Feature flag to enforce Route reuse in native way provided from Taurus NgRx. * * - Introduced for backward compatibility. * - Default value is false, and continues to operate like previous major version. * - If set to true will enforce Route reuse strategy and will re-initialize Component with new Model for the new params. */ enforceRouteReuse: boolean; /** * ** Model subscription ref. * @private */ private _modelSubscription; /** * ** Constructor. */ protected constructor(componentService: ComponentService, navigationService: NavigationService, activatedRoute: ActivatedRoute, className?: string); /** * ** Navigate to page using {@link NavigationService.navigateTo}. */ navigateTo(replaceValues?: { [key: string]: ArrayElement<TaurusNavigateAction['replacers']>['replaceValue']; }): Promise<boolean>; /** * ** Navigate back to previous page using {@link NavigationService.navigateBack}. */ navigateBack(replaceValues?: { [key: string]: ArrayElement<TaurusNavigateAction['replacers']>['replaceValue']; }): Promise<boolean>; /** * @inheritDoc */ ngOnInit(): void; /** * @inheritDoc */ ngOnDestroy(): void; /** * ** Invoking method register subscriber for Taurus NgRx Redux Store mutation in context of {@link ComponentState.routePathSegments}, * which binds {@link ComponentModel} to {@link TaurusBaseComponent.model} * and start invocation of Taurus NgRx Redux Component lifecycle hooks. * * <b>Invocation order:</b> * * 1. {@link OnTaurusModelInit} * 2. {@link OnTaurusModelInitialLoad} or {@link OnTaurusModelFirstLoad} - only one could be invoke, * where deprecated shouldn't be implemented anymore. * 3. {@link OnTaurusModelLoad} * 4. {@link OnTaurusModelChange} when status is {@link LOADED} * 5. {@link OnTaurusModelError} or {@link OnTaurusModelFail} when status is {@link FAILED} - only one could be invoke, * where deprecated shouldn't be implemented anymore. * * <p> * <br> * Override it if you want to change default behavior. * </p> * * @protected */ protected bindModel(): void; /** * ** Evaluates Taurus NgRx Redux Component lifecycle hooks * ({@link OnTaurusModelLoad} and {@link OnTaurusModelChange} and ({@link OnTaurusModelFail} or {@link OnTaurusModelError})). * * - Override it if you want to change default behavior. * * @protected */ protected evaluateTaurusComponentLifecycleHooks(model: ComponentModel): void; /** * ** Refresh model field {@link TaurusBaseComponent.model} with new one, * and assigns previous model reference to field {@link ComponentModel.previousModel} in the new model, * to the max depth 3. * * - All assignments are by reference. * - Override it if you want to change default behavior. * - <b>Be cautious about your changes and intents!</b> It could affect features thar depend on this method Impl. * * @protected */ protected refreshModel(model: ComponentModel): void; /** * ** Normalize Model state, by default it clear Task field in {@link ComponentState.task} and update model in Taurus NgRx Redux Store. * * - It is invoked only if {@link ComponentModel} is modified and after invocation of all Taurus components lifecycle hooks. * - Override it if you want to change default behavior. * * @protected */ protected normalizeModelState(model: ComponentModel): void; /** * ** Set Model state in IDLE to stop listening on Events from Store. * * - It is invoked by default before Component is destroyed, in Angular lifecycle hook {@link OnDestroy}. * - Override it if you want to change default behavior. * * @protected */ protected setStateIdle(): void; /** * ** Evaluation of this method acknowledge that new {@link ComponentModel} is modified or not. * * - Comparison is evaluated between provided Model and assigned Component's Model {@link TaurusBaseComponent.model}. * - Default implementation use {@link ComponentModel.isModified} for deep Comparison of specific fields. * - Override it if you want to change default behavior. * * <p> * <b>Be cautious about your changes and intents!</b> * Examples what can wrong comparison do? * </p> * * 1. Infinite lifecycle hooks invocation, where consequences are: performance deterioration or application freeze. * 2. Prevent lifecycle hooks invocation, where consequences are: your Data never arrive to your Component fields. * * @protected */ protected isModelModified(model: ComponentModel): boolean; /** * ** Initialize Route reuse strategy for Component in context of Taurus NgRx. * - Turns on listener for Activated params change and if detects mutation * sets current model in current RoutePathSegment to idle, * and bind for new model stream to the new RoutePathSegment. * - New feature this is completely backward compatible, * and it can be turned on with feature flag per Component Class. * * @protected */ protected initializeRouteReuse(): void; /** * ** Invoke Taurus NgRx Redux Component lifecycle hook. * * - Lifecycle hooks are invoked only if implementation they are found as implemented in subclasses. * - Returns true if method is found and executed, otherwise false. * * @private */ private static _executeTaurusComponentHook; static ɵfac: i0.ɵɵFactoryDeclaration<TaurusBaseComponent, never>; static ɵdir: i0.ɵɵDirectiveDeclaration<TaurusBaseComponent, never, never, {}, {}, never>; }