wip: extracting core cont'd - allow arbitrary number of arguments to transformation
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 6 Dec 2013 11:46:25 +0000 (12:46 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sun, 15 Dec 2013 21:32:48 +0000 (22:32 +0100)
src/smartxml/smartxml.js
src/smartxml/transformations.js

index 2ed9c47..b28f8d1 100644 (file)
@@ -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)
     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);
     }
 };
         return instance.transform(Transformation, args);
     }
 };
index a5a84df..5f0756c 100644 (file)
@@ -19,27 +19,44 @@ toret.createGenericTransformation = function(desc, name) {
     desc = getTransDesc(desc);
     
     var GenericTransformation = function(document, args) {
     desc = getTransDesc(desc);
     
     var GenericTransformation = function(document, args) {
-        this.args = args || {};
+        this.args = args || [];
 
         var transformation = this;
 
         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) {
                     get: function() {
                         if(transformation.hasRun) {
-                            //console.log('returning via path');
                             return transformation.document.getNodeByPath(path);
                         } else {
                             return transformation.document.getNodeByPath(path);
                         } else {
-                            //console.log('returning original arg');
-                            return value;
-
+                            return arg;
                         }
                     }
                 });
             }
         });
                         }
                     }
                 });
             }
         });
+
         this.document = document;
         this.hasRun = false;
         if(desc.init) {
         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();
             }
                 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;
         },
             this.hasRun = true;
             return toret;
         },