Refactor stamp component and observe element changes so subsequent "connect" messages will be sent

This commit is contained in:
Jay Ohms
2026-03-17 08:12:57 -04:00
parent 00b588fcef
commit 5c1f3a1f4f
@@ -5,22 +5,40 @@ export default class extends BridgeComponent {
static values = { scopeSelector: { type: String, default: "body" } }
connect() {
super.connect()
if (this.element.closest(this.scopeSelectorValue)) {
super.connect()
this.send("connect", this.#data)
this.notifyBridgeOfConnect()
this.#observeStamp()
}
}
disconnect() {
super.disconnect()
this.notifyBridgeOfDisconnect()
this.stampObserver?.disconnect()
}
notifyBridgeOfConnect() {
const bridgeElement = this.bridgeElement
this.send("connect", {
title: bridgeElement.title,
description: bridgeElement.bridgeAttribute("description")
})
}
notifyBridgeOfDisconnect() {
this.send("disconnect")
}
get #data() {
const bridgeElement = this.bridgeElement
return {
title: bridgeElement.title,
description: bridgeElement.bridgeAttribute("description") ?? null
}
#observeStamp() {
this.stampObserver = new MutationObserver(() => {
this.notifyBridgeOfConnect()
})
this.stampObserver.observe(this.element, {
attributes: true
})
}
}