mitt icon indicating copy to clipboard operation
mitt copied to clipboard

Arbitrary number of emit() arguments using rest/spread

Open shuckster opened this issue 4 years ago • 0 comments

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! :)

shuckster avatar Aug 13 '20 18:08 shuckster