X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/6a1f491170e661583c77cba9103e981555a454b3..95c5dcadaaa2aabdeb0bfa3d0987450c0e63dae3:/src/smartxml/transformations.js?ds=sidebyside diff --git a/src/smartxml/transformations.js b/src/smartxml/transformations.js index 3b1073f..a2a9f48 100644 --- a/src/smartxml/transformations.js +++ b/src/smartxml/transformations.js @@ -5,6 +5,7 @@ define(function(require) { var _ = require('libs/underscore'), toret = {}; + var getTransDesc = function(desc) { if(typeof desc === 'function') { desc = {impl: desc}; @@ -20,28 +21,7 @@ toret.createGenericTransformation = function(desc, name) { var GenericTransformation = function(document, args) { this.args = args || []; - var transformation = this; - // _.keys(this.args).forEach(function(key) { - // if(transformation.args[key].nodeType) { //@@ change to instanceof check, fix circular dependency - // var value = transformation.args[key], - // path = value.getPath(); - // Object.defineProperty(transformation.args, key, { - // get: function() { - // if(transformation.hasRun) { - // //console.log('returning via path'); - // return transformation.document.getNodeByPath(path); - // } else { - // //console.log('returning original arg'); - // return value; - - // } - // } - // }); - // } - // }); - - // potem spr na dotychczasowych undo/redo tests; var patchObject = function(obj, depth) { depth = _.isNumber(depth) ? depth : 1; @@ -71,7 +51,7 @@ toret.createGenericTransformation = function(desc, name) { }); this.document = document; - this.hasRun = false; + this.runCount = 0; if(desc.init) { desc.init.call(this); } @@ -93,7 +73,7 @@ toret.createGenericTransformation = function(desc, name) { } var argsToPass = desc.undo ? [this].concat(this.args) : this.args; var toret = desc.impl.apply(this.context, argsToPass); - this.hasRun = true; + this.runCount++; return toret; }, undo: function() { @@ -108,6 +88,7 @@ toret.createGenericTransformation = function(desc, name) { }, wrapNodeProperty: function(object, propName, value) { var transformation = this, + lastRunNumber = 0, path; value = value || object[propName]; @@ -115,11 +96,11 @@ toret.createGenericTransformation = function(desc, name) { path = value.getPath(); Object.defineProperty(object, propName, { get: function() { - if(transformation.hasRun && path) { - return transformation.document.getNodeByPath(path); - } else { - return value; + if((lastRunNumber !== transformation.runCount) && path) { + value = transformation.document.getNodeByPath(path); + lastRunNumber = transformation.runCount; } + return value; } }); }