Skip to content

Commit

Permalink
Revert "chore: use constructor in examples/broadcast.ts"
Browse files Browse the repository at this point in the history
This reverts commit da12f67.
  • Loading branch information
hugojosefson committed Jul 11, 2023
1 parent 541a37f commit 889d4ee
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<unknown>) => {
Expand Down
4 changes: 2 additions & 2 deletions examples/broadcast.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<unknown>) => {
Expand Down
7 changes: 2 additions & 5 deletions src/web-socket-broadcast-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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),
Expand Down

0 comments on commit 889d4ee

Please sign in to comment.