From cc910033cd33f0564f0ae11a8ca80f97f62a9d0a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 24 Jan 2014 14:09:54 +0100 Subject: [PATCH] smartxml: transformations fix - wrapping nodes arguments with path accessor one level deeper --- src/smartxml/transformations.js | 43 +++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/smartxml/transformations.js b/src/smartxml/transformations.js index 053ed10..0d2012e 100644 --- a/src/smartxml/transformations.js +++ b/src/smartxml/transformations.js @@ -43,6 +43,32 @@ toret.createGenericTransformation = function(desc, name) { // potem spr na dotychczasowych undo/redo tests; + var patchObject = function(obj, depth) { + depth = _.isNumber(depth) ? depth : 1; + if(depth > 3) { + return; + } + _.keys(obj).forEach(function(key) { + var value = obj[key], + path; + if(value) { + if(value.nodeType) { + path = value.getPath(); + Object.defineProperty(obj, key, { + get: function() { + if(transformation.hasRun && path) { + return transformation.document.getNodeByPath(path); + } else { + return value; + } + } + }); + } else if(_.isObject(value)) { + patchObject(value, depth+1); + } + } + }); + }; this.args.forEach(function(arg, idx, args) { var path; @@ -59,22 +85,7 @@ toret.createGenericTransformation = function(desc, name) { } }); } else if(_.isObject(arg)) { - _.keys(arg).forEach(function(key) { - var value = arg[key], - path; - if(value && value.nodeType) { - path = value.getPath(); - Object.defineProperty(arg, key, { - get: function() { - if(transformation.hasRun && path) { - return transformation.document.getNodeByPath(path); - } else { - return value; - } - } - }); - } - }); + patchObject(arg); } } }); -- 2.20.1