-
-
Save aaronj1335/7026900 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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