SteveSanderson/knockout — Issue #203: Bug with simple scenario kb.dependentObservable in KO1.2.1
Author: kmalakoff
Created: 2011-11-14 21:34:05+00:00
State: open

A week ago, I submitted a patch that didn't turn out to be necessary. However, as part of the patch, I also had included an unrelated bug fix.

Today, I encountered it again in a non-patched version of KO and was able to strip it down to a simple test case: http://jsfiddle.net/kmalakoff/X5qej/2/

I encountered it twice today and found out the source of problems was identical. This is the patch...basically making sure the _latestValue is updated:

function dependentObservable() {
if (arguments.length > 0) {
if (typeof options["write"] === "function") {
// Writing a value
var valueToWrite = arguments[0];
options["owner"] ? options["write"].call(options["owner"], valueToWrite) : options["write"](valueToWrite);
....
evaluate(); // update the cached value in _latestValue
....
} else {
throw "Cannot write a value to a dependentObservable unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters.";
}

Note: in one of my cases: "_latestValue = valueToWrite;" was enough to fix the problem, but in the other, it was not so the full fix ended up being "evaluate();" I can't extract the second case right now, but if you needed it, I can try later this week.

Cheers,

Kevin