-
Notifications
You must be signed in to change notification settings - Fork 436
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
Star handlers called without the event type as the first arg #2
Comments
heh! I only realized after publishing that I'd made the wrong call there but then tweeted the right one. Thanks for the PR. |
just sorry for the offtopic... @oaleynik which is that theme that you are using? I'm new to Atom and trying to find some meaningful theme for syntax. |
@tunnckoCore that's actually my editor - I commented with the setup in this issue (apparently people really like my editor setup haha). |
Haha, great & thanks. I'll try the syntax theme. Few weeks on Atom and can't find meaningful theme, tried dozen but all are absolutely awful. |
@tunnckoCore yeah, that screenshot is the ctrl+c/ctrl+v from Twitter :) Some other themes I like include:
It of course depends on the mood, time of the day when I work, moon phase, etc.. :) @developit very sorry for the offtopic :) |
One Dark Vivid for life (though now I'm looking at Gloom) |
@oaleynik holy shit, so clean and enough, I'll try it, because screenshot is not enough for me :) Thanks again. So TJ is still so amazing person, haha.
meh.. it happens some times 😆 |
Btw, a bit on topic. What about that (fixes #2 - this, resolves #12, 197b and in bonus: you can access the let ret = {
all: {},
on (type, handler) {
list(type).push(handler)
return ret
},
off (type, handler) {
let e = list(type)
e.splice(e.indexOf(handler) >>> 0, 1)
return ret
},
emit (type, event) {
list(type).map((f) => f(event))
list('*').map((f) => f(type, event))
return ret
}
}
let list = (type) => ret.all[type = type.toLowerCase()] || (ret.all[type] = [])
module.exports = () => ret |
Damn, I'm god? 🚀 179b with #8 let mitt = {
all: {},
on (type, handler) {
list(type).add(handler)
return mitt
},
off (type, handler) {
list(type).delete(handler)
return mitt
},
emit (type, event) {
list(type).forEach( f => f(event))
list('*').forEach( f => f(type, event))
return mitt
}
}
let list = (type) => mitt.all[type = type.toLowerCase()] || (mitt.all[type] = new Set())
export default () => mitt usage var mitt = require('./dist/mitt')
var ee = mitt()
ee
.on('*', (type, arg) => console.log('wildcard:', type, arg))
.on('foo', (arg) => console.log('foo1:', arg))
.on('foo', (arg) => console.log('foo2:', arg))
.on('bar', (arg) => console.log('bar:', arg))
.emit('foo', 123)
.emit('bar', 444) edit: so we freely can implement multiple args - we have huge room :D |
@tunnckoCore your implementation returns the same instance for every |
Hm. Actually, yea. I get some tests. |
Looks like all star handlers should be called with
type
as first argument, aren't they?The text was updated successfully, but these errors were encountered: