Skip to content
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

suggest to make 'createEvents' type friendley #955

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/history/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1015,13 +1015,15 @@ function promptBeforeUnload(event: BeforeUnloadEvent) {
event.returnValue = "";
}

type Events<F> = {
type EventHandler = (...args: any[]) => any;

type Events<F extends EventHandler> = {
length: number;
push: (fn: F) => () => void;
call: (arg: any) => void;
call: (...arg: Parameters<F>) => void;
};

function createEvents<F extends Function>(): Events<F> {
function createEvents<F extends EventHandler>(): Events<F> {
let handlers: F[] = [];

return {
Expand All @@ -1034,8 +1036,8 @@ function createEvents<F extends Function>(): Events<F> {
handlers = handlers.filter((handler) => handler !== fn);
};
},
call(arg) {
handlers.forEach((fn) => fn && fn(arg));
call(...arg) {
handlers.forEach((fn) => fn && fn(...arg));
},
};
}
Expand Down