In the following fiddle: http://jsfiddle.net/3Lqsx/2088/
I've bound the second button to a function that reverses the direction of the counter.
If I click the button, the new binding doesn't apply until after I click the first button once. It should take effect immediately.
How to I force this new binding to take effect immediately?
Code:
var ClickCounterViewModel = function() {
this.numberOfClicks = ko.observable(0);
this.registerClick = function() {
this.numberOfClicks(this.numberOfClicks() + 1);
};
this.changeClickBinding = function() {
$('#clicker').attr('data-bind', 'click: function(){numberOfClicks(numberOfClicks() - 1)}');
};
this.resetClicks = function() {
this.numberOfClicks(0);
};
this.hasClickedTooManyTimes = ko.computed(function() {
return this.numberOfClicks() >= 3;
}, this);
};
ko.applyBindings(new ClickCounterViewModel());