Skip to content

Instantly share code, notes, and snippets.

@aaronj1335
Last active December 25, 2015 19:19
Show Gist options
  • Select an option

  • Save aaronj1335/7026900 to your computer and use it in GitHub Desktop.

Select an option

Save aaronj1335/7026900 to your computer and use it in GitHub Desktop.
diff --git a/webapps/msgme3.0/scripts/msgme/ko/mapping.js b/webapps/msgme3.0/scripts/msgme/ko/mapping.js
index 9ac150e..5439cb7 100644
--- a/webapps/msgme3.0/scripts/msgme/ko/mapping.js
+++ b/webapps/msgme3.0/scripts/msgme/ko/mapping.js
@@ -116,6 +116,14 @@ function ($, _, ko, komapping, deep) {
}
}
+ function isObservableArray(oa) {
+ return oa &&
+ oa.hasOwnProperty('length') &&
+ oa.hasOwnProperty('indexOf') &&
+ oa.hasOwnProperty('slice') &&
+ _.isFunction(oa);
+ }
+
komapping.fromJS =
function msgme_ko_fromJS (source, mapping, target, rootModel) {
mapping = deep.clone(mapping || {});
@@ -150,7 +158,18 @@ function ($, _, ko, komapping, deep) {
if (!target._mapping) {
fixupNestedMappings(source, mapping, rootModel || target);
+ var arraysToRestore = _.reduce(args[0],
+ function (arraysToRestore, val, prop) {
+ if (isObservableArray(val) && !target.hasOwnProperty(prop)) {
+ arraysToRestore.push(prop);
+ }
+ return arraysToRestore;
+ }, []);
fromJS.apply(komapping, args);
+ _.each(arraysToRestore, function (prop) {
+ console.log('doing it',prop);
+ target[prop] = args[0][prop];
+ });
target._mapping = mapping;
} else {
args[1] = mapping = target._mapping;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment