I've been playing around with Knockout recently and I'm trying to replace a $("").change handler with a subscription to a ko computed observable.
The issue I have is that when I'm making an ajax call inside a computed observable with knockout, firebug doesn't break on the debugger keyword or any breakpoints inside the success callback, but works fine when the ajax is fired in the $().change handler.
The code appears to work though, but I'm interested to see if anyone knows why it doesn't stop at the breakpoint?
Here is the original code, which breaks on the success call back fine:
$("#textarea").change(function() {
$.ajax({
//code elided
success : function(response){
debugger
alert(response);
};
});
});
And here is the code in knockout.
function ViewModel(){
var self = this;
self.textValue = ko.observable();
self.throttledValue = ko.computed(this.textValue)
.extend({ throttle: 400 });
this.throttledValue.subscribe(function (val) {
if (val !== ''){
$.ajax({
//code elided
success : function(response){
debugger
alert(response);
};
});
}
});
};
I hope the above illustrates what I'm doing.
Essentially, both will display the alert with the response from the ajax call, so we know the success function is being called,but only the first one will stop on "debugger".
Can anyone shed light on this behaviour? is it something to do with it being inside the subscribe to the throttledValue computed observable?
Again, the code still works, just interested to see if anyone knows why the break point isn't being hit.