Skip to content

Commit

Permalink
Refine event on method types
Browse files Browse the repository at this point in the history
  • Loading branch information
craigbeck committed Mar 18, 2024
1 parent 4f3c12a commit ea93285
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Model/EventMapTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class EventMapTree {
if (next) {
node = next;
} else {
node = new EventMapTree(node, segment);
node = new EventMapTree(node, segment.toString());
children.set(segment, node);
}
}
Expand Down
24 changes: 18 additions & 6 deletions src/Model/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export interface ModelOnEventMap {
}

declare module './Model' {
interface Model {
interface Model<T> {
addListener(event: string, listener: any, arg2?: any, arg3?: any): any;
eventContext(id: string): Model;
eventContext(id: string): ChildModel<T>;

/**
* Listen to Racer events matching a certain path or path pattern.
Expand Down Expand Up @@ -63,20 +63,32 @@ declare module './Model' {
pathPattern: PathLike,
options: { useEventObjects: true },
listener: (event: ModelOnEventMap[T], captures: Array<string | string[]>) => void
): Function;
): () => void;
on<T extends keyof ModelOnEventMap>(
eventType: T,
options: { useEventObjects: true },
listener: (event: ModelOnEventMap[T], captures: Array<string | string[]>) => void
): Function;
): () => void;

// TODO review this calling w/o options if options useEventObjects should go away
// without any "legacy" events use case
on<T extends keyof ModelOnEventMap>(
eventType: T,
pathPattern: PathLike,
listener: (event: ModelOnEventMap[T], captures: Array<string | string[]>) => void
): () => void;
on<T extends keyof ModelOnEventMap>(
eventType: T,
listener: (event: ModelOnEventMap[T], captures: Array<string | string[]>) => void
): () => void;
on(
eventType: 'all',
listener: (segments: string[], event: ModelOnEventMap[keyof ModelOnEventMap]) => void
): Function;
): () => void;
on(
eventType: 'error',
listener: (error: Error) => void
): Function;
): () => void;


/**
Expand Down

0 comments on commit ea93285

Please sign in to comment.