Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@developit
Copy link
Owner

@developit developit commented May 26, 2020

This is a follow-up to #99 that reduces size a bit by caching the result of handlers.get() and reusing that value for both the existence check (are any handlers registered) and the index calculation.

@github-actions
Copy link

github-actions bot commented May 26, 2020

Size Change: -18 B (1%)

Total Size: 930 B

Filename Size Change
dist/mitt.es.js 213 B -6 B (2%)
dist/mitt.js 213 B -2 B (0%)
dist/mitt.modern.js 212 B -6 B (2%)
dist/mitt.umd.js 292 B -4 B (1%)

compressed-size-action

all.get(type).splice(all.get(type).indexOf(handler) >>> 0, 1);
const handlers = all.get(type);
if (handlers) {
handlers.splice(handlers.indexOf(handler) >>> 0, 1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to use Set for the handlers instead?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For speed yes, but Set rejects duplicates. EventEmitter, the API contract mitt adheres to, allows duplicate handlers.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean I can register the same functions twice? That is really interesting.

@developit developit merged commit 3bce9a1 into master May 27, 2020
@developit developit deleted the map-cache-size branch May 27, 2020 16:33
@developit
Copy link
Owner Author

Released in 2.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants