Skip to content

Instantly share code, notes, and snippets.

@louy
Created July 10, 2014 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save louy/24c7de977f758ee9c40f to your computer and use it in GitHub Desktop.
Save louy/24c7de977f758ee9c40f to your computer and use it in GitHub Desktop.
Subscribe with Old and New Value for Knockout Subscribable
ko.subscribable.fn.subscribeChanged = function( callback ) {
var oldValue;
return [
this.subscribe( function( _oldValue ) {
oldValue = _oldValue;
}, this, 'beforeChange' ),
this.subscribe( function( newValue ) {
callback( newValue, oldValue );
} )
];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment