fix: call star handlers with type as first parameter#3
fix: call star handlers with type as first parameter#3oaleynik wants to merge 1 commit intodevelopit:masterfrom
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