Skip to content

Conversation

@jaylinski
Copy link
Contributor

@jaylinski jaylinski commented Jun 3, 2020

Description

Adds a clear() function, as discussed in #72 (comment).

As noted in #72 (comment), implementing a "clear all events"-functionality via off() can be problematic, since events passed in the mitt all-param will get removed.
The clear()-method is more expressive in what it does.

Is an alternative to #105.

Is Map.clear() supported by all major browsers?

Yes. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear

Relates to

#70 #72 #102

@jaylinski
Copy link
Contributor Author

Error: compressed-size-action was unable to comment on your PR.
This can happen for PR's originating from a fork without write permissions.
You can copy the size table directly into a comment using the markdown below:

Size Change: +51 B (5%) 🔍

Total Size: 981 B

Filename Size Change
dist/mitt.es.js 227 B +14 B (6%) 🔍
dist/mitt.js 227 B +14 B (6%) 🔍
dist/mitt.modern.js 222 B +10 B (4%)
dist/mitt.umd.js 305 B +13 B (4%)

@developit
Copy link
Owner

developit commented Jun 9, 2020

I think I prefer this version, but I'm thinking of ways to offset the size impact.

Good call on the method name too, using clear is "free" since it's already in the dictionary due to map.clear().

@jaylinski
Copy link
Contributor Author

jaylinski commented Jun 9, 2020

Regarding size: the only thing I can think of would be to shorten the name from clear to rm (for remove) (now I get what you meant by "is already in the dictionary").

This is the size output when I run npm run build:

Build "mitt" to dist:
        198 B: mitt.js.gz
        189 B: mitt.js.br
        191 B: mitt.modern.js.gz
        164 B: mitt.modern.js.br
        196 B: mitt.es.js.gz
        191 B: mitt.es.js.br
        276 B: mitt.umd.js.gz
        234 B: mitt.umd.js.br

So still below 200 B on modern gz. :)

@jaylinski
Copy link
Contributor Author

@developit Is there any chance you will merge and tag this in the next week or so?

(Otherwise I'll create my own fork in the meantime.)

@developit
Copy link
Owner

@jaylinski would you be okay if we merged the .all version instead? (your #105)

@jaylinski
Copy link
Contributor Author

@jaylinski would you be okay if we merged the .all version instead? (your #105)

Yes, would be okay for me.

@developit
Copy link
Owner

closing now that #105 is merged!

@developit developit closed this Jul 15, 2020
@jaylinski jaylinski deleted the clear branch July 15, 2020 14:47
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.

2 participants