Skip to content

Commit

Permalink
Dependent observables without a write function also don't get a proxy…
Browse files Browse the repository at this point in the history
… write function. Closes #91.
  • Loading branch information
sagacity committed Jul 23, 2012
1 parent 001a83b commit 66c07f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion knockout.mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
}
return DO.apply(DO, arguments);
},
write: function (val) {
write: DO.hasWriteFunction && function (val) {
return DO(val);
},
deferEvaluation: true
Expand Down
24 changes: 23 additions & 1 deletion spec/proxyDependentObservableBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var generateProxyTests = function(useComputed) {

testStart[moduleName] = function() {
test = {
evaluationCount: 0
evaluationCount: 0,
writeEvaluationCount: 0
};
test.create = function(createOptions) {
var obj = {
Expand All @@ -34,6 +35,13 @@ var generateProxyTests = function(useComputed) {
deferEvaluation: !!createOptions.deferEvaluation
}, mapped);
}
else if (createOptions.useWriteCallback) {
mapped.DO = func({
read: DOdata,
write: function(value) { test.written = value; test.writeEvaluationCount++; },
deferEvaluation: !!createOptions.deferEvaluation
}, mapped);
}
else {
mapped.DO = func(DOdata, mapped, {
deferEvaluation: !!createOptions.deferEvaluation
Expand Down Expand Up @@ -197,6 +205,20 @@ var generateProxyTests = function(useComputed) {
equal(vm.inner1.DOprop(), vm);
});

test('dependentObservables with a write callback are passed through', function() {
var mapped = test.create({ useWriteCallback: true });
equal(mapped.a.DO.hasWriteFunction, true);

mapped.a.DO("hello");
equal(test.written, "hello");
equal(test.writeEvaluationCount, 1);
});

test('dependentObservables without a write callback do not get a write callback', function() {
var mapped = test.create({ useWriteCallback: false });
equal(mapped.a.DO.hasWriteFunction, false);
});

asyncTest('undeferred dependentObservables that are NOT used immediately SHOULD be auto-evaluated after mapping', function() {
var mapped = test.create();
window.setTimeout(function() {
Expand Down

0 comments on commit 66c07f8

Please sign in to comment.