libs/core/building-blocks/src/lib/facade/abstract-building-block-facade.ts
No results matching.
Properties |
Methods |
Accessors |
constructor(buildingBlock: BuildingBlockInterface)
|
||||||
|
Parameters :
|
| _isConnected |
Type : unknown
|
Default value : false
|
| connected$ |
Type : unknown
|
Default value : new Subject<void>()
|
| disconnected$ |
Type : unknown
|
Default value : new Subject<void>()
|
| cleanupValidationHandling | ||||||
cleanupValidationHandling(form: UntypedFormGroup)
|
||||||
|
Parameters :
Returns :
void
|
| connect |
connect()
|
|
TODO: Implement proper lifecycle Building Blocks will connect when being discovered on a page this means we can define a lifecycle here. Before Connection: Feature Flags, Resources & State Connect N/A After Connection established: Complete by telling the BB so (onPageConnection)
Returns :
void
|
| Static create | ||||||
create(block: BuildingBlockInterface)
|
||||||
|
Parameters :
Returns :
AbstractBuildingBlockFacade
|
| disconnect |
disconnect()
|
|
Returns :
void
|
| markFormGroupAsTouched |
markFormGroupAsTouched()
|
|
Returns :
void
|
| id |
getid()
|
import { UntypedFormGroup } from '@angular/forms';
import { Subject } from 'rxjs';
import { BuildingBlockInterface } from '../building-block/building-block-interface';
export class AbstractBuildingBlockFacade {
_isConnected = false;
disconnected$ = new Subject<void>();
connected$ = new Subject<void>();
get id() {
return this.buildingBlock?.id;
}
static create(block: BuildingBlockInterface) {
return new AbstractBuildingBlockFacade(block);
}
constructor(readonly buildingBlock: BuildingBlockInterface) {
if (!this.buildingBlock) {
throw new Error('You tried to create a Facade without a Building Block');
}
if (!this.id) {
throw new Error(`Could not read derive from given Building Block. Received ${this.id}`);
}
}
/**
* TODO: Implement proper lifecycle
* Building Blocks will connect when being discovered on a page
* this means we can define a lifecycle here.
* Before Connection: Feature Flags, Resources & State
* Connect N/A
* After Connection established: Complete by telling the BB so (onPageConnection)
*/
connect() {
if (this._isConnected) {
console.warn(`Can't connect facade ${this.id}, already connected`);
return;
}
this._isConnected = true;
this.connected$.next();
this.buildingBlock.connected$.next();
this.buildingBlock.onPageConnection();
}
cleanupValidationHandling(form: UntypedFormGroup): void {
throw new Error('cleanupValidationHandling must be implemented in the specific Facade');
}
disconnect() {
if (!this._isConnected) {
console.warn(`Can't disconnect facade ${this.id}, not connected`);
return;
}
this._isConnected = false;
this.disconnected$.next();
this.buildingBlock.disconnected$.next();
this.buildingBlock.onPageDisconnected();
const form = this.buildingBlock.getForm();
if (form) {
this.cleanupValidationHandling(form);
}
}
markFormGroupAsTouched() {
this.buildingBlock.getForm()?.markAllAsTouched();
}
}