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

If emitter.off provides only the event, remove all listeners for that event. #124

Merged
merged 3 commits into from Jun 22, 2021

Conversation

sealice
Copy link
Contributor

@sealice sealice commented Jan 4, 2021

This solves the #123 issue.

		off<T = any>(type: EventType, handler?: Handler<T>) {
			const handlers = all.get(type);
			if (handlers) {
		            if(handler){
				handlers.splice(handlers.indexOf(handler) >>> 0, 1);
		            } else {
		                all.delete(type);
		            }
			}
		},

If emitter.off provides only the event, remove all listeners for that event.
@andreyrd
Copy link

andreyrd commented Jan 8, 2021

Looks like this needs some formatting fixes and it should be good to go!
I just ran into a bug in my own project, I was using this as a mostly drop in replacement for a Vue-based bus, and it assumes everywhere that all event listeners are removed when the function handle is left out.

@sealice
Copy link
Contributor Author

sealice commented Jan 11, 2021

@andreyrd Thanks, I am going to fix the format.

@redfox05
Copy link

redfox05 commented Mar 17, 2021

Quick note, could this be adjusted to allow for partial/wildcard matching? So we can remove listeners written in a namespaced format.

event.off('myComponent1.addMenuItem')

Which could then be used to remove all listeners for a component on destroy, rather than listing each one, potentially missing some. I'm happy to add the code myself if needed in another PR.

@sealice
Copy link
Contributor Author

sealice commented Mar 19, 2021

Quick note, could this be adjusted to allow for partial/wildcard matching? So we can remove listeners written in a namespaced format.

event.off('myComponent1.addMenuItem')

Which could then be used to remove all listeners for a component on destroy, rather than listing each one, potentially missing some. I'm happy to add the code myself if needed in another PR.

This is a good idea, you are welcome to submit your own ideas.

@sealice sealice mentioned this pull request Mar 20, 2021
@workforbala
Copy link

what happened to this PR awaiting for this feature

@developit developit self-requested a review May 16, 2021 22:55
@mariusa
Copy link

mariusa commented Jun 16, 2021

@developit ping & thanks

developit added a commit that referenced this pull request Jun 22, 2021
@developit developit merged commit 53eb689 into developit:master Jun 22, 2021
@developit
Copy link
Owner

This will be released as 3.0.0.

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.

None yet

6 participants