chrisdavies / eev

A tiny, fast, zero-dependency event emitter
522 stars 32 forks source link

Making callback of event's `of` as optional #5

Closed gokatz closed 6 years ago

gokatz commented 6 years ago

by this line, we made the callback to of as mandatory which will not a case for many scenarios. Can we make this as optional? Happy to raise a PR. 😃

chrisdavies commented 6 years ago

Ah. I see what you're saying.

var e = new Eev();

function foo(data) {console.log("FOO");}

e.off('bar', foo);

That code blows up because foo is not a registered event handler. I'm happy to take a pull request! Should be as simple as putting an if statement in there.

gokatz commented 6 years ago

I'm unaware of the uglifyjs version you are using to minify the changes. Can you mention that in the package.json?

chrisdavies commented 6 years ago

Yeah. I originally wrote this back before I really knew much about npm! I'll put an update together. Also, I can just go ahead and fix the bug, unless you want to get credited with a pull request. Let me know!

chrisdavies commented 6 years ago

Well, I went ahead and fixed both! But this has made me want to revisit this project and modernize it a bit. We'll see if I can set aside the time to do that.

Thanks!

gokatz commented 6 years ago

Thanks for the update @chrisdavies and I would love to know if postMessage could be a good alternative.

chrisdavies commented 6 years ago

That's an interesting idea! postMessage is designed to solve a different problem from generic event emission (what Eev does). I think you could probably use postMessage for the same purpose if you're programming in the browser. It wouldn't work on Node, though, which can make unit testing more of a pain.