-
Notifications
You must be signed in to change notification settings - Fork 438
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
fix: call star handlers with type as first parameter #3
Conversation
Awesome, thanks Oleg! |
Shouldn't it be the second parameter? I'd expect the first parameter to be the same regardless of how the event it's registered. |
It could be better like this: ...
emit(type, ...args) {
const data = { type: type, args: args };
list('*').concat(list(type)).forEach(f => f(data));
}
... Usage: import mitt from 'mitt';
const emitter = mitt();
emitter.on('*', ({type, args}) => {
console.log(type);
args.forEach(a => console.log(a));
});
emitter.on('auth', ({type, args}) => {
console.log(type);
args.forEach(a => console.log(a));
});
emitter.emit('auth', {a: 'b'}, {c: 'd'});
emitter.emit('success', 'foo', 'bar'); |
Currently only one argument is supported. |
@developit, in first glance it not looks good. But I review the full And actually, why not just support #13 multiple arguments emit(type, a, b, c, d) {
(all[type = type.toLowerCase()] || []).map( f => { f(type, a, b, c, d); });
return ret;
} yea it will lowercase when edit: btw, add |
@tunnckoCore will add The issue with your suggestion is that it adds |
Actually yea, realized that after few moments ;d just didn't sleep last night. |
Fixed in #19 |
Closes #2