Last active
August 29, 2015 14:01
-
-
Save bahattincinic/8a253d08b428b127f5ca to your computer and use it in GitHub Desktop.
Knockout Js Custom Subscribe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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