Evan & Eric - using underscore's "once" method would work, however, it
won't actually remove the subscription from amplify. I've put
together a quick and dirty example of implementing your own "once"
wrapper around amplify's subscribe call:
var slice = [].slice,
once = function( topic, context, callback, priority ) {
if ( arguments.length === 3 && typeof callback === "number" )
{
callback = context;
}
else if ( arguments.length === 2 ) {
callback = context;
}
var fn = function() {
callback.apply(this, slice.call(arguments,0));
amplify.unsubscribe(topic, fn);
}
return amplify.subscribe( topic, context, fn, priority );
};
You can see a working fiddle example of the code here:
http://jsfiddle.net/ifandelse/XUWEr/
Hope that helps!
> To get that effect, you can wrap your function in _.once()
http://documentcloud.github.com/underscore/#once
>
>
>
>
>
>
>
> On Monday, February 27, 2012 12:02:07 PM UTC-5, Evan Davis wrote:
>
> > Bump! It'd be great to have a way to unsubscribe anonymous functions as
> > well; something like *amplify.subscribeOnce(topic, callback)* would be