UNPKG

@plotinus/matrix-package-observable-coordinator

Version:

Observable coordinator pattern components using IntrospectableBaseCommunicationComponent and proper presentation architecture

149 lines (148 loc) 10.7 kB
/** * ======================================================================================================== * 🎯 APP PRESENTATION ELEMENT - REAL-TIME INTROSPECTION UI COMPONENT * ======================================================================================================== * * This custom HTML element demonstrates the PRESENTATION LAYER of the Matrix Framework's * IntrospectableBaseCommunicationComponent pattern. It provides real-time visualization * of observable state changes and events from the AppComponent communication layer. * * 🔥 INTROSPECTION PATTERNS DEMONSTRATED: * ──────────────────────────────────────────────────────────────────────────────────────────────────── * • Real-time State Observation: Listens to _stateChanged events for automatic UI updates * • Property-Level Tracking: Responds to _propertyChanged events for granular change detection * • Event Emission Monitoring: Observes _eventEmitted events for complete system transparency * • Two-Way Communication: UI interactions trigger communication component methods * • Presentation Layer Separation: Pure presentation logic separate from business logic * * 🎭 PRESENTATION RESPONSIBILITIES: * ──────────────────────────────────────────────────────────────────────────────────────────────────── * • Subscribe to introspection events from bound communication component * • Provide real-time UI updates based on observable state changes * • Display system status: coordinator readiness, processing state, job completion * • Offer UI controls for triggering system operations (Start Processing button) * • Maintain presentation-specific state (log messages, UI interactions) * * 🚀 EVENT-DRIVEN UI LIFECYCLE: * ──────────────────────────────────────────────────────────────────────────────────────────────────── * 1. bindTo() → Subscribe to communication component's introspection events * 2. onStateChanged() → Re-render UI when observable state changes * 3. onPropertyChanged() → Update specific UI elements when individual properties change * 4. User interactions → Trigger communication component methods via direct calls * 5. Log display → Track all events and state changes for debugging visibility * * ======================================================================================================== */ /** * 🎯 AppPresentationElement - Custom Element for Observable State Visualization * * Extends HTMLElement to provide: * • Shadow DOM encapsulation for isolated presentation styling * • Event-driven UI updates based on communication component introspection * • Real-time logging and state display for system transparency * • User interaction controls that trigger communication component methods */ export declare class AppPresentationElement extends HTMLElement { private commComponent; private logMessages; /** * 🏗️ Element Construction - Setting Up Presentation Infrastructure * ══════════════════════════════════════════════════════════════════════════════════════════════════ * * Initializes the custom element with Shadow DOM and presentation-specific state. * This demonstrates clean separation between presentation state (logMessages) * and communication component state (managed by AppComponent). */ constructor(); /** * 🔗 Component Binding - The Core Introspection Connection * ══════════════════════════════════════════════════════════════════════════════════════════════════ * * This method establishes the CRITICAL connection between the presentation layer and the * communication component's introspection system. It subscribes to three key introspection * events that enable real-time UI updates based on observable state changes. * * INTROSPECTION EVENTS SUBSCRIBED: * • _stateChanged: Full state object updates (triggers complete UI re-render) * • _propertyChanged: Individual property updates (triggers targeted UI updates) * • _eventEmitted: Component event emissions (for debugging and system transparency) */ bindTo(commComponent: any): void; /** * 🎨 UI Rendering - State-Driven Dynamic Display * ══════════════════════════════════════════════════════════════════════════════════════════════════ * * This method demonstrates REACTIVE UI PATTERNS where the presentation layer * automatically updates based on observable state changes from the communication component. * It transforms abstract state data into visual indicators and user-friendly status displays. * * RENDERING PATTERNS DEMONSTRATED: * • State-to-UI Mapping: Convert boolean/array state to visual status indicators * • Conditional UI Elements: Show/hide elements based on state values * • Real-time Data Binding: Automatic UI updates when state changes via introspection * • Presentation State Integration: Combine communication state with UI-specific data */ render(): void; /** * 🚀 User Interaction Handler - UI-to-Communication Bridge * ══════════════════════════════════════════════════════════════════════════════════════════════════ * * This method demonstrates the TWO-WAY COMMUNICATION pattern where UI interactions * trigger communication component methods. The presentation layer acts as a bridge * between user actions and the observable communication layer. * * INTERACTION FLOW: * Button click → startProcessing() → commComponent.handleStartProcessing() → setState() → introspection events → UI updates */ startProcessing(): void; /** * 📋 Presentation Logging - UI-Specific State Management * ══════════════════════════════════════════════════════════════════════════════════════════════════ * * This method demonstrates PRESENTATION-SPECIFIC STATE management separate from * communication component observable state. It maintains UI-only data (log messages) * and provides targeted DOM updates to avoid infinite render loops. * * PRESENTATION STATE PATTERNS: * • UI-Only Data: logMessages array is presentation-specific, not part of communication state * • Targeted Updates: Update only the logger section to avoid triggering full re-renders * • Circular Reference Prevention: Careful not to call this from render() method */ logToUI(message: string): void; /** * 🔄 State Change Handler - Observable State Response * ══════════════════════════════════════════════════════════════════════════════════════════════════ * * This method is called automatically when the communication component's setState() method * is called, demonstrating the REACTIVE UI PATTERN core to the Matrix Framework's * introspection system. It shows how presentation layers stay synchronized with business logic. * * INTROSPECTION EVENT FLOW: * setState() in AppComponent → _stateChanged event → this.onStateChanged() → render() → UI updates */ onStateChanged(newState: any): void; /** * 📝 Property Change Handler - Granular State Tracking * ══════════════════════════════════════════════════════════════════════════════════════════════════ * * This method provides GRANULAR CHANGE TRACKING for individual properties within the * observable state. It's called for each property that changes when setState() is called, * enabling detailed monitoring and potentially targeted UI updates. * * GRANULAR INTROSPECTION PATTERN: * setState({prop1: val1, prop2: val2}) → triggers onPropertyChanged() twice → individual property tracking */ onPropertyChanged(propertyName: string, newValue: any, oldValue: any): void; /** * 🔌 DOM Connection Lifecycle - Web Component Integration * ══════════════════════════════════════════════════════════════════════════════════════════════════ * * This Web Components lifecycle method is called when the element is added to the DOM. * It demonstrates the integration between Matrix Framework components and standard * Web Components lifecycle, ensuring proper initialization and rendering. * * WEB COMPONENT LIFECYCLE INTEGRATION: * Element creation → constructor() → bindTo() → connectedCallback() → DOM ready */ connectedCallback(): void; }