@plotinus/matrix-package-observable-coordinator
Version:
Observable coordinator pattern components using IntrospectableBaseCommunicationComponent and proper presentation architecture
29 lines (28 loc) • 961 B
JavaScript
export class WorkerPresentationElement extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
bindTo(commComponent) {
this.commComponent = commComponent;
// Subscribe to state changes
if (commComponent.eventBus) {
const stateKey = `cmp:${commComponent.id}:_stateChanged`;
commComponent.eventBus.on(stateKey, () => this.render());
}
this.render();
}
render() {
const state = this.commComponent?.state || {};
this.shadowRoot.innerHTML = `
<style>
:host { display: block; }
.worker { border: 2px solid #3fb950; padding: 12px; margin: 8px; border-radius: 6px; }
</style>
<div class="worker">
<h4>Worker: ${this.commComponent?.id}</h4>
<div>Jobs: ${state.jobsProcessed || 0}</div>
</div>
`;
}
}