Skip to content

Commit

Permalink
Fix ko.mapping.visitModel which may be called without options.
Browse files Browse the repository at this point in the history
Do we need really export it?
  • Loading branch information
DzenisevichK committed Apr 10, 2012
1 parent 4b61529 commit 4743603
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions knockout.mapping.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
options = mergeOptions(rootObject[mappingProperty], options); options = mergeOptions(rootObject[mappingProperty], options);


// We just unwrap everything at every level in the object graph // We just unwrap everything at every level in the object graph
return exports.visitModel(rootObject, function (x) { return visitModel(rootObject, function (x) {
return ko.utils.unwrapObservable(x) return ko.utils.unwrapObservable(x)
}, options); }, options);
}; };
Expand All @@ -117,6 +117,14 @@
return ko.utils.stringifyJson(plainJavaScriptObject); return ko.utils.stringifyJson(plainJavaScriptObject);
}; };


exports.visitModel = function (rootObject, callback, options) {
if (arguments.length == 0) throw new Error("When calling ko.mapping.visitModel, pass the object you want to visit.");
// Merge in the options used in fromJS
options = mergeOptions(rootObject[mappingProperty], options);

return visitModel(rootObject, callback, options);
};

exports.defaultOptions = function () { exports.defaultOptions = function () {
if (arguments.length > 0) { if (arguments.length > 0) {
defaultOptions = arguments[0]; defaultOptions = arguments[0];
Expand Down Expand Up @@ -591,9 +599,7 @@
return propertyName; return propertyName;
} }


exports.visitModel = function (rootObject, callback, options, /* internal */ parentName) { function visitModel(rootObject, callback, options, parentName) {
options = options || {};

// If nested object was already mapped previously, take the options from it // If nested object was already mapped previously, take the options from it
if (parentName !== undefined && exports.isMapped(rootObject)) { if (parentName !== undefined && exports.isMapped(rootObject)) {
options = ko.utils.unwrapObservable(rootObject)[mappingProperty]; options = ko.utils.unwrapObservable(rootObject)[mappingProperty];
Expand Down Expand Up @@ -642,7 +648,7 @@
case "array": case "array":
case "undefined": case "undefined":
var previouslyMappedValue = visitedObjects.get(propertyValue); var previouslyMappedValue = visitedObjects.get(propertyValue);
mappedRootObject[indexer] = (exports.getType(previouslyMappedValue) !== "undefined") ? previouslyMappedValue : exports.visitModel(propertyValue, callback, options, fullPropertyName); mappedRootObject[indexer] = (exports.getType(previouslyMappedValue) !== "undefined") ? previouslyMappedValue : visitModel(propertyValue, callback, options, fullPropertyName);
break; break;
default: default:
mappedRootObject[indexer] = callback(propertyValue, parentName); mappedRootObject[indexer] = callback(propertyValue, parentName);
Expand Down

0 comments on commit 4743603

Please sign in to comment.