Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions build/output/knockout.mapping-latest.debug.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Knockout Mapping plugin v2.4.1
/// (c) 2013 Steven Sanderson, Roy Jacobs - http://knockoutjs.com/
/// License: MIT (http://www.opensource.org/licenses/mit-license.php)
/// Knockout Mapping plugin v2.4.1
/// (c) 2013 Steven Sanderson, Roy Jacobs - http://knockoutjs.com/
/// License: MIT (http://www.opensource.org/licenses/mit-license.php)
(function (factory) {
// Module systems magic dance.

Expand Down Expand Up @@ -303,6 +303,49 @@
}

function updateViewModel(mappedRootObject, rootObject, options, parentName, parent, parentPropertyName, mappedParent) {

////////////////////////////////////////////////////////////////////////
/**
* example: add normalize function to your mapping definition, like create or update.
* if in your update or create callbacks you expect for example an object, and you receive
* a String, you can normalize the data using normalize callback:
* normalize: function( options ){
* if (!$.isPlainObject( options.data ) options.data = {};
* return options.data;
* }
*
* */


var hasNormalizeCallback = function () {
return options[parentName] && options[parentName].normalize instanceof Function;
};

var normalizeCallback = function (obj, data) {
var params = {
data: data || rootObject,
parent: mappedParent || parent,
target: ko.utils.unwrapObservable(obj)
};

if (ko.isWriteableObservable(obj)) {
params.observable = obj;
}

return options[parentName].normalize(params);
};

if( hasNormalizeCallback() ){
rootObject = normalizeCallback( mappedRootObject );
}

////////////////////////////////////////////////////////////////////////






var isArray = exports.getType(ko.utils.unwrapObservable(rootObject)) === "array";

parentPropertyName = parentPropertyName || "";
Expand Down