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

addEventListenerOnce method #473

Closed
cvisto opened this issue Feb 8, 2012 · 9 comments
Closed

addEventListenerOnce method #473

cvisto opened this issue Feb 8, 2012 · 9 comments
Assignees
Labels
Milestone

Comments

@cvisto
Copy link

cvisto commented Feb 8, 2012

I was faced with the need to add the same listener function to different objects while listener of one object has to fire once and listener of another object has to fire any time event is created.

Now I should resolve this task like this:

myFunc(){
alert('clicked');
}

myFunc_Once(){
marker1.removeEventListener('click', myFunc_Once);
myFunc();
}

Init(){
marker1.addEventListener('click', myFunc_Once);
marker2.addEventListener('click', myFunc);
}

It would be more easy to use addEventListenerOnce wich will make event listener to remove itself after firing.

@ghost ghost assigned mourner Feb 13, 2012
@mourner
Copy link
Member

mourner commented Feb 13, 2012

Agree this would be nice to have in future.

@cvisto
Copy link
Author

cvisto commented Feb 13, 2012

Great. I need this method for puposes of my development. I want to create it right now. And when it will be clear for me how to make a pull request I will sent new code for your recenzasion (in order you could add it to preferable releaze). Is this way suitable to you?

@mourner
Copy link
Member

mourner commented Feb 13, 2012

Sure, looking forward to your pull!

@cvisto
Copy link
Author

cvisto commented Mar 23, 2012

I made a pull request

@cvisto
Copy link
Author

cvisto commented Mar 23, 2012

also I created another two methods that were very useful for me. Perhaps they will suit for someone else

  • hasEventListener(type, fn, context) - checks if there is an exact handler of event type
  • clearEventListeners(type) - removes all handlers for the specified event type

Should I add them to pull request mentioned above or make a new one?

@doxav
Copy link

doxav commented May 4, 2012

Cvisto,

Could you please provide your code for "hasEventListener(type, fn, context)" and "clearEventListeners(type)".

Thanks a lot!

@cvisto
Copy link
Author

cvisto commented May 5, 2012

methods start from here https://github.com/cvisto/Leaflet/blob/has_clearEventListeners/src/core/Events.js#L23. You can get them from there or just merge my has_clearEventListeners branch

@MatthewRuddy
Copy link

This one seems like a bit of a no-brainer here. Definitely think it should be implemented. Odd in-fact that it hasn't already. Have had to do on-offs three times now in the same application which isn't so neat and tidy. Add it guys! :)

@mourner mourner mentioned this issue Apr 19, 2013
@mourner
Copy link
Member

mourner commented Apr 19, 2013

Done.

@mourner mourner closed this as completed Apr 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants