Skip to content

Conversation

@mikhail-angelov
Copy link

It will be good if on() function returns unsubscribe function

@developit
Copy link
Owner

Love the idea! Need to figure out a way to keep this under 200b though ;)

@mjackson
Copy link

Save some space by removing the off method?

@developit
Copy link
Owner

That'd break compat with EventEmitter though. I had wondered if bind() would be shorter.

@loopmode
Copy link

Renaming :) list -> l, type -> t

@developit
Copy link
Owner

@loopmode that's currently done via Uglify as a build step - the 200b size cap we're tracking is actually on the ES3 output.

@mjackson
Copy link

@developit Doesn't seem like compat is that important, is it? node's EventEmitter API doesn't even have off. They use removeListener instead.

@developit
Copy link
Owner

True, I always forget that. I was using WildEmitter prior to writing this, which has on/off. Touché 😉

@tunnckoCore
Copy link
Collaborator

tunnckoCore commented Jan 16, 2017

@mjackson yea, but it is well-known convention and it feels more natural than returning unsubs from on

@developit
Copy link
Owner

I've done both and would love to support both if we can squeeze it in. The bind technique should make it pretty cheap 👍

@mikhail-angelov
Copy link
Author

I've tried different implementation to reduce size of final lib, but no luck, I'm getting 38 bites more.
Look's like this initial statement (200b) is too strong since initial version was about this size. :(

@dotproto dotproto mentioned this pull request Jan 17, 2017
@dotproto
Copy link
Contributor

dotproto commented Jan 17, 2017

Here's a technique for manually creating an unsubscribe function.

let e = mitt();
function handler() {}
e.on('foo', handler);
let unsub = e.off.bind(e, 'foo', handler);

@ajoslin
Copy link

ajoslin commented Feb 28, 2017

I think I found a way, opening a PR.

ajoslin added a commit to ajoslin/mitt that referenced this pull request Feb 28, 2017
ajoslin added a commit to ajoslin/mitt that referenced this pull request Feb 28, 2017
ajoslin added a commit to ajoslin/mitt that referenced this pull request Feb 28, 2017
ajoslin added a commit to ajoslin/mitt that referenced this pull request Feb 28, 2017
ajoslin added a commit to ajoslin/mitt that referenced this pull request Feb 28, 2017
ajoslin added a commit to ajoslin/mitt that referenced this pull request Feb 28, 2017
ajoslin added a commit to ajoslin/mitt that referenced this pull request Feb 28, 2017
ajoslin added a commit to ajoslin/mitt that referenced this pull request Feb 28, 2017
@developit
Copy link
Owner

closing in favor of #42

@developit developit closed this Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants