From: Aleksander Ɓukasz Date: Fri, 6 Dec 2013 11:46:25 +0000 (+0100) Subject: wip: extracting core cont'd - allow arbitrary number of arguments to transformation X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/2a63804a0f4838a7016c84735df10dde26f8bb38?ds=sidebyside wip: extracting core cont'd - allow arbitrary number of arguments to transformation --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 2ed9c47..b28f8d1 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -235,8 +235,9 @@ var registerTransformation = function(desc, name, target) { var Transformation = transformations.createContextTransformation(desc, name); //+ to sie powinna nazywac registerTransformationFromDesc or sth //+ ew. spr czy nie override (tylko jesli powyzej sa prototypy to trudno do nich dojsc) - target[name] = function(args) { - var instance = this; + target[name] = function() { + var instance = this, + args = Array.prototype.slice.call(arguments, 0); return instance.transform(Transformation, args); } }; diff --git a/src/smartxml/transformations.js b/src/smartxml/transformations.js index a5a84df..5f0756c 100644 --- a/src/smartxml/transformations.js +++ b/src/smartxml/transformations.js @@ -19,27 +19,44 @@ toret.createGenericTransformation = function(desc, name) { desc = getTransDesc(desc); var GenericTransformation = function(document, args) { - this.args = 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, { + // _.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; + this.args.forEach(function(arg, idx, args) { + if(arg.nodeType) { // ~ + var path = arg.getPath(); + Object.defineProperty(args, idx, { get: function() { if(transformation.hasRun) { - //console.log('returning via path'); return transformation.document.getNodeByPath(path); } else { - //console.log('returning original arg'); - return value; - + return arg; } } }); } }); + this.document = document; this.hasRun = false; if(desc.init) { @@ -55,7 +72,8 @@ toret.createGenericTransformation = function(desc, name) { this.snapshot = changeRoot.clone(); this.changeRootPath = changeRoot.getPath(); } - var toret = desc.impl.call(this.context, this.args); // a argumenty do metody? + //var toret = desc.impl.call(this.context, this.args); // a argumenty do metody? + var toret = desc.impl.apply(this.context, this.args); this.hasRun = true; return toret; },