Skip to content

Commit

Permalink
feat: support numeric event name (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
lisez authored May 25, 2024
1 parent 41bff4f commit 4f76227
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type EventName = string | symbol;
export type EventName = string | symbol | number;

export type ConjoinEvents = [EventName, EventName, ...EventName[]];

Expand Down
11 changes: 11 additions & 0 deletions tests/deno/multiple_events_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ describe("Xevt - multiple events", () => {
assert(count === 2, `Expected 2, got ${count}`);
});

it("should listen numeric events", () => {
const emitter = new Xevt();
let result = 0;
emitter.on([0, 1], () => {
result++;
});
emitter.emit(0);
emitter.emit(1);
assert(result === 1, `Expected 1, got ${result}`);
});

it("should listen multiple handlers", () => {
const emitter = new Xevt();
const result: number[] = [];
Expand Down
10 changes: 10 additions & 0 deletions tests/deno/single_event_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ describe("Xevt - single event", () => {
assert(result === 1, `Expected 1, got ${result}`);
});

it("should listen numeric events", () => {
const emitter = new Xevt();
let result = 0;
emitter.on(1, () => {
result++;
});
emitter.emit(1);
assert(result === 1, `Expected 1, got ${result}`);
});

it("should listen event multiple times", () => {
const emitter = new Xevt();

Expand Down

0 comments on commit 4f76227

Please sign in to comment.