Skip to content
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

Request to Implement Unsubscribe Functionality in the Mitt Framework #202

Open
wcldyx opened this issue Sep 5, 2024 · 0 comments
Open

Comments

@wcldyx
Copy link

wcldyx commented Sep 5, 2024

Request to Implement Unsubscribe Functionality in the Mitt Framework

Description:
The current version of the Mitt framework lacks an unsubscribe feature, making it inconvenient to manage event listeners, especially when components are unmounted or no longer need to listen for events.

Suggested Feature:
Implement an unsubscribe method that allows users to easily remove specific event listeners.

Example:

// Current usage in Mitt
const mitt = require('mitt');
const emitter = mitt();

const handler = () => console.log('Event triggered');
emitter.on('event', handler);
emitter.off('event', handler); 
// After adding the unsubscribe feature
const mitt = require('mitt');
const emitter = mitt();

// Proposed usage
const unsubscribe = emitter.on('event', () => console.log('Event triggered'));
unsubscribe(); // Now we can easily unsubscribe

Conclusion:
Adding the unsubscribe functionality would greatly improve the usability of the Mitt framework and align it with best practices in event handling. Thank you for considering this enhancement!

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

No branches or pull requests

1 participant