Skip to content

Instantly share code, notes, and snippets.

@Vchekryzhov
Created June 19, 2018 19:45
Show Gist options
  • Save Vchekryzhov/0793571f4ec9012bbdd3af12aa32f391 to your computer and use it in GitHub Desktop.
Save Vchekryzhov/0793571f4ec9012bbdd3af12aa32f391 to your computer and use it in GitHub Desktop.
subscribe knockout with old value
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