diff options
Diffstat (limited to 'src/server-component.mjs')
-rw-r--r-- | src/server-component.mjs | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/server-component.mjs b/src/server-component.mjs index b7aec2c..373f4cd 100644 --- a/src/server-component.mjs +++ b/src/server-component.mjs @@ -63,22 +63,26 @@ export class LustreServerComponent extends HTMLElement { this.#socket?.close(); this.#socket = new WebSocket(`ws://${window.location.host}${route}`); - this.#socket.addEventListener("message", ({ data }) => { - const [kind, ...payload] = JSON.parse(data); + this.#socket.addEventListener("message", (message) => + this.messageReceivedCallback(message), + ); + } + } + } + } - switch (kind) { - case Constants.diff: - return this.diff(payload); + messageReceivedCallback({ data }) { + const [kind, ...payload] = JSON.parse(data); - case Constants.emit: - return this.emit(payload); + switch (kind) { + case Constants.diff: + return this.diff(payload); - case Constants.init: - return this.init(payload); - } - }); - } - } + case Constants.emit: + return this.emit(payload); + + case Constants.init: + return this.init(payload); } } @@ -107,7 +111,7 @@ export class LustreServerComponent extends HTMLElement { if (prev !== value) { this.#socket?.send( - JSON.stringify([Constants.attrs, [[attr, value]]]) + JSON.stringify([Constants.attrs, [[attr, value]]]), ); } }, |