mitt
mitt copied to clipboard
Arbitrary number of emit() arguments using rest/spread
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! :)