File
Index
Properties
|
|
Methods
|
|
Accessors
|
|
_isConnected
|
Default value : false
|
|
connected$
|
Default value : new Subject<void>()
|
|
disconnected$
|
Default value : new Subject<void>()
|
|
Methods
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)
|
markFormGroupAsTouched
|
markFormGroupAsTouched()
|
|
|
import { Subject } from 'rxjs';
import { BuildingBlockInterface } from '../building-block/building-block-interface';
import { cleanupValidationHandling } from '../form-support/validation';
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();
}
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) {
cleanupValidationHandling(form);
}
}
markFormGroupAsTouched() {
this.buildingBlock.getForm()?.markAllAsTouched();
}
}