From 889d4ee1066b5d350588d4c049aac8b778155ba2 Mon Sep 17 00:00:00 2001 From: Hugo Josefson Date: Wed, 12 Jul 2023 00:55:48 +0200 Subject: [PATCH] Revert "chore: use constructor in examples/broadcast.ts" This reverts commit da12f675a26929d3d666f10d89c040b4547e0940. --- README.md | 4 ++-- examples/broadcast.ts | 4 ++-- src/web-socket-broadcast-channel.ts | 7 ++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 57c2f13..98103ae 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ function to create the relevant `BroadcastChannel` object, and then uses the `BroadcastChannel` API as usual. ```typescript -import { WebSocketBroadcastChannel } from "https://deno.land/x/websocket_broadcastchannel/mod.ts"; +import { createBroadcastChannel } from "https://deno.land/x/websocket_broadcastchannel/mod.ts"; const pid = Deno.pid; const pidLastDigit = pid % 10; @@ -77,7 +77,7 @@ const log = (s: string, ...args: unknown[]) => { log("run this in multiple terminals on the same host, to see it work"); log("starting..."); -const testChannel = new WebSocketBroadcastChannel("test"); +const testChannel = createBroadcastChannel("test"); log("testChannel.constructor.name", testChannel.constructor.name); testChannel.onmessage = (event: MessageEvent) => { diff --git a/examples/broadcast.ts b/examples/broadcast.ts index 7b25549..9a646c0 100755 --- a/examples/broadcast.ts +++ b/examples/broadcast.ts @@ -1,5 +1,5 @@ #!/usr/bin/env -S deno run --allow-net --watch -import { WebSocketBroadcastChannel } from "../mod.ts"; +import { createBroadcastChannel } from "../mod.ts"; const pid = Deno.pid; const pidLastDigit = pid % 10; @@ -12,7 +12,7 @@ const log = (s: string, ...args: unknown[]) => { log("run this in multiple terminals on the same host, to see it work"); log("starting..."); -const testChannel = new WebSocketBroadcastChannel("test"); +const testChannel = createBroadcastChannel("test"); log("testChannel.constructor.name", testChannel.constructor.name); testChannel.onmessage = (event: MessageEvent) => { diff --git a/src/web-socket-broadcast-channel.ts b/src/web-socket-broadcast-channel.ts index 1a99d76..769ca3e 100644 --- a/src/web-socket-broadcast-channel.ts +++ b/src/web-socket-broadcast-channel.ts @@ -38,7 +38,7 @@ const log0: Logger = logger(import.meta.url); export class WebSocketBroadcastChannel extends EventTarget implements BroadcastChannelIsh, Disposable { readonly uuid: string = crypto.randomUUID(); - onmessage: ((ev: MessageEvent) => void) | null = null; + onmessage: ((ev: Event) => void) | null = null; onmessageerror: ((ev: Event) => void) | null = null; private readonly log: Logger = log0.sub(WebSocketBroadcastChannel.name); private closeFuse = new OneTimeFuse("channel is already closed"); @@ -57,10 +57,7 @@ export class WebSocketBroadcastChannel extends EventTarget super(); this.log.sub("constructor")(`name: ${s(name)}, url: ${s(url)}`); this.idUrlChannel = IdUrlChannel.of(IdUrl.of(url), name); - this.addEventListener( - "message", - (e: Event) => this.onmessage?.(e as MessageEvent), - ); + this.addEventListener("message", (e: Event) => this.onmessage?.(e)); this.addEventListener( "messageerror", (e: Event) => this.onmessageerror?.(e),