-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
event.off is not removing the event #123
Comments
If mitt.off provides only the event, remove all listeners for that event.
How to solve this problem now? |
.off(name, handler) func means mitt will remove |
Manually deleting event : |
I'm assuming the above solution is not ideal / might be messing with internal logic, so is it not possible to make the .off() function take an optional handler instead of required, and if handler is missing, delete all handlers with that label? Then it would work the same as @acuD1's workaround. Update: That seems to be exactly what has been implemented in #124 but not yet an approved/merged PR. |
if both handler having same call back function name how we can differentiate between which one is on and which one is off ? |
Our usecase is defining a handler inline, not as a separate function, eg
This isn't enough. Doesn't work for inline listeners. |
yes, we'd better not use inline listener, cus |
It seems that off is not working or I am missing something.
I am using mitt it in Vue 3
`import mitt from "mitt";
const Event = mitt();
const app = createApp(App);
app.config.globalProperties.Event = Event;
app.mount('#app');`
I have 2 components Category and CategoryDetails and when changing from one to another it seems that the off is not "destroying" the event.
In CategoryDetails component:
mounted() { const vm = this; this.Event.on('category.save', function(){ vm.formSubmit(); }); },
// it should clear the event - to no longer emit
unmounted() { this.Event.off('category.save'); }
Entering again in CateegoryDetails and emits the save, it make 2 request and so on....
I have tried to use in unmounted:
this.Event.all.clear();
and seems to work.
Why is not working if I specify the event name to off ???
Am i missing something ?
The text was updated successfully, but these errors were encountered: