Skip to content

Request to Implement Unsubscribe Functionality in the Mitt Framework #202

Open
@wcldyx

Description

@wcldyx

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions