-
Notifications
You must be signed in to change notification settings - Fork 48
feat: allow string event names #2618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ describe("StreamManager", () => { | |
| createMockStream({ id: "1", protocol: MULTICODEC, writeStatus }) | ||
| ]; | ||
|
|
||
| streamManager["libp2p"]["connectionManager"]["getConnections"] = ( | ||
| (streamManager["libp2p"]["connectionManager"] as any).getConnections = ( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we avoid the |
||
| _peerId: PeerId | undefined | ||
| ) => [con1]; | ||
|
|
||
|
|
@@ -46,7 +46,7 @@ describe("StreamManager", () => { | |
| }); | ||
|
|
||
| it("should return undefined if no connection provided", async () => { | ||
| streamManager["libp2p"]["connectionManager"]["getConnections"] = ( | ||
| (streamManager["libp2p"]["connectionManager"] as any).getConnections = ( | ||
| _peerId: PeerId | undefined | ||
| ) => []; | ||
|
|
||
|
|
@@ -70,7 +70,7 @@ describe("StreamManager", () => { | |
| ); | ||
|
|
||
| con1.newStream = newStreamSpy; | ||
| streamManager["libp2p"]["connectionManager"]["getConnections"] = ( | ||
| (streamManager["libp2p"]["connectionManager"] as any).getConnections = ( | ||
| _peerId: PeerId | undefined | ||
| ) => [con1]; | ||
|
|
||
|
|
@@ -97,7 +97,7 @@ describe("StreamManager", () => { | |
| ); | ||
|
|
||
| con1.newStream = newStreamSpy; | ||
| streamManager["libp2p"]["connectionManager"]["getConnections"] = ( | ||
| (streamManager["libp2p"]["connectionManager"] as any).getConnections = ( | ||
| _peerId: PeerId | undefined | ||
| ) => [con1]; | ||
|
|
||
|
|
@@ -148,7 +148,7 @@ describe("StreamManager", () => { | |
| writeStatus: "writable" | ||
| }) | ||
| ]; | ||
| streamManager["libp2p"]["connectionManager"]["getConnections"] = ( | ||
| (streamManager["libp2p"]["connectionManager"] as any).getConnections = ( | ||
| _id: PeerId | undefined | ||
| ) => [con1]; | ||
|
|
||
|
|
@@ -178,7 +178,6 @@ function createMockConnection(options: MockConnectionOptions = {}): Connection { | |
| } | ||
| } as Connection; | ||
| } | ||
|
|
||
| type MockStreamOptions = { | ||
| id?: string; | ||
| protocol?: string; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,33 +25,35 @@ export type CreateEncoderParams = CreateDecoderParams & { | |
| ephemeral?: boolean; | ||
| }; | ||
|
|
||
| export enum WakuEvent { | ||
| Connection = "waku:connection", | ||
| Health = "waku:health" | ||
| } | ||
| export const WakuEvent = { | ||
| Connection: "waku:connection", | ||
| Health: "waku:health" | ||
| } as const; | ||
|
Comment on lines
+28
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought you wanted to remove the enum? In any case, add a comment for next implementer to say to leave it as is to expose string for event types to developer. |
||
|
|
||
| export type WakuEvent = (typeof WakuEvent)[keyof typeof WakuEvent]; | ||
|
|
||
| export interface IWakuEvents { | ||
| /** | ||
| * Emitted when a connection is established or lost. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * waku.addEventListener(WakuEvent.Connection, (event) => { | ||
| * waku.events.addEventListener("waku:connection", (event) => { | ||
| * console.log(event.detail); // true if connected, false if disconnected | ||
| * }); | ||
| */ | ||
| [WakuEvent.Connection]: CustomEvent<boolean>; | ||
| "waku:connection": CustomEvent<boolean>; | ||
|
|
||
| /** | ||
| * Emitted when the health status changes. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * waku.addEventListener(WakuEvent.Health, (event) => { | ||
| * waku.events.addEventListener("waku:health", (event) => { | ||
| * console.log(event.detail); // 'Unhealthy', 'MinimallyHealthy', or 'SufficientlyHealthy' | ||
| * }); | ||
| */ | ||
| [WakuEvent.Health]: CustomEvent<HealthStatus>; | ||
| "waku:health": CustomEvent<HealthStatus>; | ||
| } | ||
|
|
||
| export type IWakuEventEmitter = TypedEventEmitter<IWakuEvents>; | ||
|
|
@@ -66,12 +68,12 @@ export interface IWaku { | |
| /** | ||
| * Emits events related to the Waku node. | ||
| * Those are: | ||
| * - WakuEvent.Connection | ||
| * - WakuEvent.Health | ||
| * - "waku:connection" | ||
| * - "waku:health" | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * waku.events.addEventListener(WakuEvent.Connection, (event) => { | ||
| * waku.events.addEventListener("waku:connection", (event) => { | ||
| * console.log(event.detail); // true if connected, false if disconnected | ||
| * }); | ||
| * ``` | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing
this.onRequestdirectly will lose thethiscontext when the method is called. SinceonRequestis now an arrow function property, this change is correct, but the arrow function should be defined before this line to ensure proper initialization order.Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What it says. I doubt you can remove the
bindhere without breaking things.this.onRequestusesthis.handleIncomingMessagewhich I believe will not be available if notbinded