Skip to content

Instantly share code, notes, and snippets.

@bahattincinic
Last active August 29, 2015 14:01
Show Gist options
  • Save bahattincinic/8a253d08b428b127f5ca to your computer and use it in GitHub Desktop.
Save bahattincinic/8a253d08b428b127f5ca to your computer and use it in GitHub Desktop.
Knockout Js Custom Subscribe
ko.subscribable.fn.subscribeChanged = function (callback, target) {
var oldValue;
this.subscribe(function (_oldValue) {
oldValue = _oldValue;
}, target, 'beforeChange');
this.subscribe(function (newValue) {
callback(newValue, oldValue, this);
}, target);
};
function Test(){
this.title = ko.observable();
this.title.subscribeChanged(function(newValue, oldValue, target){
console.log(newValue);
console.log(oldValue);
}, this);
}
var test = new Test();
ko.applyBindings(test);
test.title('deneme');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment