Comments (8)
let all = {}
let events = mitt(all)
events.reset = () => {
for (let i in all) delete all[i]
}
let off = events.off
events.off = (type, handler) => {
if (!handler) delete all[type]
else return off(type, handler)
}
from mitt.
thx, makes me to keep using mitt.
from mitt.
I'm going to crib @tunnckoCore's answer on #54 and suggest that you take a look at dush. Mitt has a very strict 200 byte limit, so adding features is a real challenge. Dush already has the behavior you described and is only slightly larger.
from mitt.
ah, I only read the issue title. Added another option.
from mitt.
thx
from mitt.
Yep. It is simple reset here.
edit: @developit, your case is for removing just all handlers, but not just all of some type like .off('foo')
. :)
from mitt.
I went for a slightly different version. Disposing of reset and adding a line to the overridden off:
events.off = (type, handler) => {
if(!type) {all ={}; return;}
if (!handler) delete all[type]
else return off(type, handler)
}
from mitt.
@ZhouHansen @mehdi-cit, in any way you add bytes, so it not make any sense to me to do that instead of just using dush
, which is exactly because of this 100-200 bytes bigger than mitt
.
Closing, since solutions are found.
from mitt.
Related Issues (20)
- Nuxt3 issues ? HOT 2
- Persist events that not yet have a handler HOT 1
- Is it possible to use mitt across two different tabs? Or via an iframe? HOT 10
- [TypeScript] define events interface HOT 3
- Mitt - some problems HOT 1
- Typescript issue with `moduleResolution: NodeNext` HOT 1
- `dist/mitt.mjs` must not have a sourcemap HOT 5
- mitt extension
- Unpkg CDN Version is down HOT 1
- Using Ag-grid cell renderer with Mitt HOT 1
- Bug: type issue in [email protected]+ with esm HOT 2
- Could we have a minor update? HOT 1
- Doesn't work with typescript 5 moduleResolution set to bundler HOT 11
- vue3 options methods use mitt Invalid HOT 1
- why use sllice & map HOT 2
- Can't pass multiple arguments with emit HOT 2
- How to declare type of event parameter when listen for event HOT 1
- error TS2349: This expression is not callable when using "module": "NodeNext". HOT 5
- Uncaught TypeError: (0 , mitt__WEBPACK_IMPORTED_MODULE_5__.default)(...) is not a function
- Emit issue on Vue 3. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mitt.