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

Arbitrary number of emit() arguments using rest/spread #115

Closed
shuckster opened this issue Aug 13, 2020 · 0 comments
Closed

Arbitrary number of emit() arguments using rest/spread #115

shuckster opened this issue Aug 13, 2020 · 0 comments
Labels
can't Out of scope / too large / too seldom-used enhancement

Comments

@shuckster
Copy link

Not sure how far this goes against your ideal of simplicity, but I wonder if you'd thought about variable arity for emit?

emit<T = any>(type: EventType, ...evt: T[]) {
  ((all.get(type) || []) as EventHandlerList)
    .slice()
    .map(handler => handler(...evt));

  ((all.get('*') || []) as WildCardEventHandlerList)
    .slice()
    .map(handler => handler(type, ...evt));
}

I'm afraid I don't know much about TypeScript so perhaps this syntax is wrong, but what do you think? I realise I could pass an array around, but just putting it out there! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't Out of scope / too large / too seldom-used enhancement
Projects
None yet
Development

No branches or pull requests

2 participants