Skip to content

Instantly share code, notes, and snippets.

@anasnakawa
Created September 3, 2015 11:39
Show Gist options
  • Save anasnakawa/a973cfed5a8717cd426a to your computer and use it in GitHub Desktop.
Save anasnakawa/a973cfed5a8717cd426a to your computer and use it in GitHub Desktop.
/**
* knockout observable subscriber that will get triggered only once at most
*
* @param {fn} handler
* @param {object} [optional] context
*/
ko.observable.fn.subscribeOnce = function( handler, context ) {
var subscribtion = this.subscribe(function() {
handler.apply( this, arguments );
subscribtion.dispose();
}, context );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment