UNPKG

@plotinus/matrix-package-observable-coordinator

Version:

Observable coordinator pattern components using IntrospectableBaseCommunicationComponent and proper presentation architecture

88 lines (76 loc) 2.88 kB
// Browser bundle for @matrix/package-observable-coordinator import { componentSources } from './browser/component-sources.js'; import { AppPresentationElement, CoordinatorPresentationElement, WorkerPresentationElement } from './presentation/index.js'; // Export everything needed for browser use export { componentSources, AppPresentationElement, CoordinatorPresentationElement, WorkerPresentationElement }; // Auto-register function for convenience export function registerObservableCoordinatorComponents(Matrix) { if (!Matrix || !Matrix.BaseCommunicationComponent) { throw new Error('Matrix framework not found'); } // Register communication components from sources const components = { app: { name: 'AppComponent', source: componentSources.appCommunication, tag: 'app' }, coordinator: { name: 'CoordinatorComponent', source: componentSources.coordinatorCommunication, tag: 'coordinator' }, worker: { name: 'WorkerComponent', source: componentSources.workerCommunication, tag: 'worker' } }; Object.values(components).forEach(comp => { try { const ComponentClass = new Function('BaseCommunicationComponent', comp.source + '\nreturn ' + comp.name )(Matrix.BaseCommunicationComponent); ComponentClass.dslTag = comp.tag; ComponentClass.isMatrixComponent = true; if (!window.MatrixComponents) { window.MatrixComponents = {}; } window.MatrixComponents[comp.name] = ComponentClass; Matrix.register(ComponentClass); console.log('Registered communication component:', comp.tag); } catch (error) { console.error('Failed to register component:', comp.name, error); } }); // Register presentation elements if (!customElements.get('app-presentation')) { customElements.define('app-presentation', AppPresentationElement); } if (!customElements.get('coordinator-presentation')) { customElements.define('coordinator-presentation', CoordinatorPresentationElement); } if (!customElements.get('worker-presentation')) { customElements.define('worker-presentation', WorkerPresentationElement); } console.log('All observable coordinator components registered'); } // Make available on window for easy access if (typeof window !== 'undefined') { window.MatrixPackageObservableCoordinator = { componentSources, AppPresentationElement, CoordinatorPresentationElement, WorkerPresentationElement, registerObservableCoordinatorComponents }; }