@versatiledatakit/shared
Version:
Versatile Data Kit Shared library enables reusability of shared features like: NgRx Redux, Error Handlers, Utils, Generic Components, etc.
102 lines (101 loc) • 4.69 kB
TypeScript
import { OnDestroy, ViewContainerRef, ViewRef } from '@angular/core';
import { TaurusObject } from '../../../common';
import * as i0 from "@angular/core";
/**
* ** Internal service model.
*/
interface AcquireViewContainerRefModel {
/**
* ** ViewContainerRef uuid.
*
* - ViewContainerRefs could be reused by providing issued UUID.
* - References are stored in the service Map where for every issued UUID key there is ViewContainerRef behind as value.
*/
uuid: string;
/**
* ** Unique ViewContainerRef created on behalf of the invoker.
*/
viewContainerRef: ViewContainerRef;
/**
* ** ViewRef to the unique ViewContainerRef created on behalf of the invoker.
*/
hostView: ViewRef;
}
/**
* ** Dynamic Components Service that generates ViewContainerRefs in context that could be used once or reused multiple times.
*/
export declare class DynamicComponentsService extends TaurusObject implements OnDestroy {
/**
* @inheritDoc
*/
static readonly CLASS_NAME: string;
/**
* ** Acquired ViewContainerRef with dependency injection during service initialization {@link DynamicComponentsService.initialize},
* where Dynamic Container {@link DynamicContainerComponent} will be inserted.
* @private
*/
private _appRootViewContainerRef;
/**
* ** Dynamic Container reference {@link DynamicContainerComponent},
* where all contextual Dynamic components {@link DynamicContextComponent} will be inserted.
* @private
*/
private _dynamicContainerRef;
/**
* ** Local store where all created Dynamic Context Components are stored under their corresponding issued UUID.
* @private
*/
private readonly _uniqueComponentRefsStore;
/**
* ** Constructor.
*/
constructor();
/**
* ** Create or retrieve unique ViewContainerRef together with ViewRef and bound UUID.
*
* - if UUID is provided it will try to retrieve such reference if exists,
* otherwise will create new ViewContainerRef which will be stored under provided UUID key.
* - if no UUID provided will proceed to issue new UUID,
* then will create new ViewContainerRef which will be stored under the issued UUID,
* and both together with ViewRef will be returned to the invoker according provided return interface.
* - if some error is thrown in process of ViewContainerRef acquisition,
* service will return <code>null</code> instead of reference and that should be handled on invoker side.
* - Currently there is no automatic garbage collection, but only manual destroy utilizing {@link this.destroyUniqueViewContainerRef},
* so be careful not to acquire too many unique ViewContainerRef references,
* because they could downgrade Application performance (they are created as Component instances in root of the application).
* - Automatic GC is not currently developed because there is possibility to retrieve existing
* contextual ViewContainerRef instances with issued UUIDs for re-usage,
* or created instances refs could be kept into the invoker scope (context),
* or instances refs could be destroyed using the provided method with issued UUIDs {@link this.destroyUniqueViewContainerRef}
*/
getUniqueViewContainerRef(requestedUUID?: string): AcquireViewContainerRefModel;
/**
* ** Destroy unique ViewContainerRef for provided UUID.
*
* - If reference is found for provided UUID and is successfully destroyed will return true otherwise false.
* - If reference for provided UUID is not found will return null.
*/
destroyUniqueViewContainerRef(uuid: string): boolean;
/**
* ** Initialize service.
*
* - Should be invoked only once.
* - Ideal place for invoking is <code>AppComponent.ngOnInit()</code>.
*/
initialize(viewContainerRef: ViewContainerRef): void;
/**
* @inheritDoc
*/
ngOnDestroy(): void;
private _createDynamicContainerComponent;
private _validateDynamicContainerComponent;
private _createDynamicContextComponent;
private _validateDynamicContextComponent;
private _clearUniqueComponentsRef;
private _clearContextContainerRef;
private _clearAppRootViewContainerRef;
private static _getOrGenerateUUID;
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicComponentsService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<DynamicComponentsService>;
}
export {};