You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm finding myself needing to attach an event handler to a key's change event only once. I'm used to jQuery's .one() method and am emulating it right now with:
functionmyStoreOne(key,fn){varhandler=function(e){store.off(key,handler);// unbind to prevent future events.returnfn.call(this,e);};store.on(key,handler);// bind to the event.}
Would be nice to be able to just call store.one(key, fn) instead.
The text was updated successfully, but these errors were encountered:
Store is extensible; if you do it like this, you make it available for all namespaces and storage areas:
store._.fn('one', function(key, fn) {
if (!fn) { fn = key; key = ''; }// no key === all keys
var s = this, _fn;
return s.on(key, _fn = function(e) {
s.off(key, _fn);
return fn.apply(this, arguments);
};
}
As for adding it to store.on, i'm not digging the store.one() naming. If you aren't friendly with jQuery.one, then it doesn't look like an event method. store.onOne is clearer, but admittedly less graceful. Maybe store.once? Argh. I'd like to believe there's always a perfect name, but alas... Failing that, what do you prefer?
I like store.one(). I know not everyone uses jQuery, but it is pretty ubiquitous.
I also like store.once(). I think that's a good compromise, and it clearly indicates what it does. I'm not sure why jQuery didn't go that route. It's much clearer.
I'm finding myself needing to attach an event handler to a key's change event only once. I'm used to jQuery's .one() method and am emulating it right now with:
Would be nice to be able to just call store.one(key, fn) instead.
The text was updated successfully, but these errors were encountered: