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
Backbone.Events.once #594
Backbone.Events.once #594
Conversation
… have the callback trigger once
Why not just use
|
'Cause otherwise it will be called every time anyway. It's useless and wasting. Unbinding permits garbage collecting every reference. |
To repeat myself from earlier this afternoon: I don't think that this is a common enough need to warrant addition to Backbone.Events ... especially when |
Just to put my grain of salt in there, I definitely see value in having such a "once" method, and
Sometimes it's an api call, sometimes it's some DOM manipulation. If I need to re-bind it later, then using |
Just came across this, thought I'd add another +1. For me, it's pretty common to only bind once in two cases: events that only happen once ( like an 'end' event), and events that happen frequently but are very decoupled from what is being hung on them ( a 'nextTick' event is an example). In both cases, it's important that references be cleaned up to prevent memory leaks. Mostly I do this in node.js, somewhat new to backbone but hit the same issue almost immediately. Cheers, |
fwiw, I could use this functionality right now |
Yesterday I also needed something like http://api.jquery.com/one/ (and _.once isn't the same) |
I'm interested in this, also. Although using This can be fixed by calling For instance, if I wanted to use jQuery.noop (as an example) as my handler, I would now have to do the following because I don't have access to the context of MyObject inside of noop:
A much more simple solution would be:
I would think that wanting an event to only fire a specific handler a single time isn't too rare of a request, and it's definitely something that should be taken account in Backbone. |
Simple event helper to bind to an event an only have the callback trigger once.