UNPKG

@plotinus/matrix-package-observable-coordinator

Version:

Observable coordinator pattern components using IntrospectableBaseCommunicationComponent and proper presentation architecture

64 lines (63 loc) 2.79 kB
// Removed EventBus import as it's no longer exported import { BaseCommunicationComponent } from '@matrix/framework'; import { logInfo, logDebug } from '@matrix/logger'; /** * The MatrixDefinitionComponent is the "outer environment" container that can * instantiate apps or other components. It can hold environment-level attributes * like 'rootTopic' and re-emit events from child apps if needed. */ export class MatrixDefinitionComponent extends BaseCommunicationComponent { // Changed EventBus type annotation to 'any' as the class is internal constructor(id, eventBus) { super(id, eventBus); logDebug(`[MatrixDefinitionComponent:${this.id}] constructor`); } onInit() { super.onInit(); logInfo(`[MatrixDefinitionComponent:${this.id}] onInit invoked`); // Example: Read an environment-level attribute like rootTopic const rootTopic = this.getAttribute('rootTopic') || 'no-topic'; logDebug(`[MatrixDefinitionComponent:${this.id}] rootTopic:`, { rootTopic }); } startExecution() { super.startExecution(); logInfo(`[MatrixDefinitionComponent:${this.id}] startExecution => environment is live.`); } /** * Example method: handle event from child <app> * if the <app> has emits="SystemCompleted:direct" and onSystemCompleted="handleAppSystemCompleted" */ handleAppSystemCompleted(evt) { logInfo(`[MatrixDefinitionComponent:${this.id}] Received SystemCompleted from child app`, evt); // Possibly bubble or finalize: this.emitEvent('SystemCompleted', evt); } /** * Handle SystemCompleted event at the matrix level * This is referenced in matrix.html with onSystemCompleted="handleMatrixSystemCompleted" */ handleMatrixSystemCompleted(evt) { logInfo(`[MatrixDefinitionComponent:${this.id}] Matrix level SystemCompleted event received`, evt); // This is the top-level handler, so we don't need to bubble up further } /** * Example method: handle another event type */ handleAnother(evt) { logInfo(`[MatrixDefinitionComponent:${this.id}] AnotherEvent fired`, evt); } // Helper to read DSL attributes if needed getAttribute(attrName) { // In NodeFactory, the "attributes" object is placed on the instance // so we can cast this as any or store them explicitly const atts = this.attributes || {}; return atts[attrName]; } // Provide debug info about environment getDebugState() { const base = super.getDebugState(); base.rootTopic = this.getAttribute('rootTopic'); return base; } } MatrixDefinitionComponent.dslTag = 'matrix-definition'; // autoRegister will discover <matrix-definition>.