Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update ko mapping to 2.3.4

  • Loading branch information...
commit 1670b91abef4eff81eb9ce79a8967f9f531bf4d2 1 parent e04ee19
Bevan Hunt authored
Showing with 26 additions and 5 deletions.
  1. +25 −4 lib/knockout/knockout.mapping.js
  2. +1 −1  smart.json
29 lib/knockout/knockout.mapping.js
View
@@ -1,4 +1,4 @@
-/// Knockout Mapping plugin v2.3.3
+/// Knockout Mapping plugin v2.3.4
/// (c) 2012 Steven Sanderson, Roy Jacobs - http://knockoutjs.com/
/// License: MIT (http://www.opensource.org/licenses/mit-license.php)
(function (factory) {
@@ -27,7 +27,8 @@
var _defaultOptions = {
include: ["_destroy"],
ignore: [],
- copy: []
+ copy: [],
+ observe: []
};
var defaultOptions = _defaultOptions;
@@ -214,12 +215,15 @@
options.ignore = mergeArrays(otherOptions.ignore, options.ignore);
options.include = mergeArrays(otherOptions.include, options.include);
options.copy = mergeArrays(otherOptions.copy, options.copy);
+ options.observe = mergeArrays(otherOptions.observe, options.observe);
}
options.ignore = mergeArrays(options.ignore, defaultOptions.ignore);
options.include = mergeArrays(options.include, defaultOptions.include);
options.copy = mergeArrays(options.copy, defaultOptions.copy);
+ options.observe = mergeArrays(options.observe, defaultOptions.observe);
options.mappedProperties = options.mappedProperties || {};
+ options.copiedProperties = options.copiedProperties || {};
return options;
}
@@ -442,12 +446,26 @@
return;
}
+ if(typeof rootObject[indexer] != "object" && typeof rootObject[indexer] != "array" && options.observe.length > 0 && ko.utils.arrayIndexOf(options.observe, fullPropertyName) == -1)
+ {
+ mappedRootObject[indexer] = rootObject[indexer];
+ options.copiedProperties[fullPropertyName] = true;
+ return;
+ }
+
// In case we are adding an already mapped property, fill it with the previously mapped property value to prevent recursion.
// If this is a property that was generated by fromJS, we should use the options specified there
var prevMappedProperty = visitedObjects.get(rootObject[indexer]);
var retval = updateViewModel(mappedRootObject[indexer], rootObject[indexer], options, indexer, mappedRootObject, fullPropertyName, mappedRootObject);
var value = prevMappedProperty || retval;
-
+
+ if(options.observe.length > 0 && ko.utils.arrayIndexOf(options.observe, fullPropertyName) == -1)
+ {
+ mappedRootObject[indexer] = value();
+ options.copiedProperties[fullPropertyName] = true;
+ return;
+ }
+
if (ko.isWriteableObservable(mappedRootObject[indexer])) {
mappedRootObject[indexer](ko.utils.unwrapObservable(value));
} else {
@@ -707,7 +725,10 @@
if (ko.utils.arrayIndexOf(options.include, indexer) === -1) {
// The mapped properties object contains all the properties that were part of the original object.
// If a property does not exist, and it is not because it is part of an array (e.g. "myProp[3]"), then it should not be unmapped.
- if (unwrappedRootObject[mappingProperty] && unwrappedRootObject[mappingProperty].mappedProperties && !unwrappedRootObject[mappingProperty].mappedProperties[indexer] && !(exports.getType(unwrappedRootObject) === "array")) {
+ if (unwrappedRootObject[mappingProperty]
+ && unwrappedRootObject[mappingProperty].mappedProperties && !unwrappedRootObject[mappingProperty].mappedProperties[indexer]
+ && unwrappedRootObject[mappingProperty].copiedProperties && !unwrappedRootObject[mappingProperty].copiedProperties[indexer]
+ && !(exports.getType(unwrappedRootObject) === "array")) {
return;
}
}
2  smart.json
View
@@ -3,6 +3,6 @@
"description": "Data bindings and form validation for Meteor. http://knockoutjs.com",
"homepage": "https://github.com/bevanhunt/meteor-knockout",
"author": "Bevan Hunt <me@bevanhunt.com> (http://www.bevanhunt.com)",
- "version": "0.2.9",
+ "version": "0.3.0",
"git": "https://github.com/bevanhunt/meteor-knockout.git"
}
Please sign in to comment.
Something went wrong with that request. Please try again.