From 5c1f3a1f4f375eaf4104cc47935dbb578c29f68f Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Tue, 17 Mar 2026 08:12:57 -0400 Subject: [PATCH] Refactor stamp component and observe element changes so subsequent "connect" messages will be sent --- .../controllers/bridge/stamp_controller.js | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/app/javascript/controllers/bridge/stamp_controller.js b/app/javascript/controllers/bridge/stamp_controller.js index 735e4c830..747f5d48d 100644 --- a/app/javascript/controllers/bridge/stamp_controller.js +++ b/app/javascript/controllers/bridge/stamp_controller.js @@ -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 + }) } }