Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing problem with the same object appearing multiple times in the s…

…ource object. Should solve #32.
  • Loading branch information...
commit 65ed6e069f617ad86cf19d7c4aba28b138534a78 1 parent 9610db4
@RoyJacobs RoyJacobs authored
Showing with 16 additions and 1 deletion.
  1. +4 −1 knockout.mapping.js
  2. +12 −0 spec/mappingBehaviors.js
View
5 knockout.mapping.js
@@ -296,7 +296,10 @@ ko.exportProperty = function (owner, publicName, object) {
return options[parentName].update(params);
}
- if (visitedObjects.get(rootObject)) return mappedRootObject;
+ var alreadyMapped = visitedObjects.get(rootObject);
+ if (alreadyMapped) {
+ return alreadyMapped;
+ }
parentName = parentName || "";
View
12 spec/mappingBehaviors.js
@@ -1522,3 +1522,15 @@ test('ko.mapping.fromJS should accept an already mapped object as the second par
ko.mapping.fromJS({ a: "b" }, mapped);
equal(mapped.a(), "b");
});
+
+test('ko.mapping.fromJS should properly map objects that appear in multiple places', function() {
+ var obj = { title: "Lorem ipsum" }, obj2 = { title: "Lorem ipsum 2" };
+ var x = [obj,obj2];
+ var y = { o: obj, x: x };
+
+ var z = ko.mapping.fromJS(y);
+ debugger;
+
+ equal(y.x[0].title, "Lorem ipsum");
+ equal(z.x()[0].title(), "Lorem ipsum");
+});
Please sign in to comment.
Something went wrong with that request. Please try again.