Permalink
Browse files

Dont wrap dependent observables if already marked as deferEvaluation

  • Loading branch information...
1 parent 01e6cbd commit 5b2c61d7f91def6c1815f379fa6c10f78d0ef8e1 @jamesfoster committed Apr 23, 2012
Showing with 41 additions and 9 deletions.
  1. +4 −3 knockout.mapping.js
  2. +37 −6 spec/proxyDependentObservableBehaviors.js
View
7 knockout.mapping.js
@@ -207,12 +207,12 @@
ko.dependentObservable = function (read, owner, options) {
options = options || {};
- var realDeferEvaluation = options.deferEvaluation;
-
if (read && typeof read == "object") { // mirrors condition in knockout implementation of DO's
options = read;
}
+ var realDeferEvaluation = options.deferEvaluation;
+
var isRemoved = false;
// We wrap the original dependent observable so that we can remove it from the 'dependentObservables' list we need to evaluate after mapping has
@@ -230,7 +230,8 @@
return DO(val);
},
deferEvaluation: true
- });
+ });
+ if(DEBUG) wrapped._wrapper = true;
return wrapped;
};
View
43 spec/proxyDependentObservableBehaviors.js
@@ -29,14 +29,17 @@ var generateProxyTests = function(useComputed) {
return "test";
};
if (createOptions.useReadCallback) {
- DOdata = {
- read: DOdata
- };
+ mapped.DO = func({
+ read: DOdata,
+ deferEvaluation: !!createOptions.deferEvaluation
+ }, mapped);
+ }
+ else {
+ mapped.DO = func(DOdata, mapped, {
+ deferEvaluation: !!createOptions.deferEvaluation
+ });
}
- mapped.DO = func(DOdata, mapped, {
- deferEvaluation: !!createOptions.deferEvaluation
- });
return mapped;
}
}
@@ -365,6 +368,34 @@ var generateProxyTests = function(useComputed) {
equal(mapped.DO.myExtension, true)
});
+
+ test('Dont wrap dependent observables if already marked as deferEvaluation', function() {
+ var obj = {
+ x: 1
+ };
+
+ var model = function(data) {
+ var _this = this;
+
+ ko.mapping.fromJS(data, {}, _this);
+
+ _this.DO1 = func(_this.x, null, {deferEvaluation: true});
+ _this.DO2 = func({read: _this.x, deferEvaluation: true});
+ _this.DO3 = func(_this.x);
+ };
+
+ var mapping = {
+ create: function(options) {
+ return new model(options.data);
+ }
+ };
+
+ var mapped = ko.mapping.fromJS(obj, mapping);
+
+ equal(mapped.DO1._wrapper, undefined);
+ equal(mapped.DO2._wrapper, undefined);
+ equal(mapped.DO3._wrapper, true);
+ });
};
generateProxyTests(false);

0 comments on commit 5b2c61d

Please sign in to comment.