Refactoring extension registration - abstract away object method registration
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 4 Dec 2013 12:02:04 +0000 (13:02 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sun, 15 Dec 2013 21:32:47 +0000 (22:32 +0100)
src/wlxml/wlxml.js

index d67fe31..8d99cde 100644 (file)
@@ -172,6 +172,9 @@ var WLXMLDocument = function(xml, options) {
     this.ElementNodeFactory.prototype.registerTransformation = function(Transformation) {
         return this.transformations.register(Transformation);
     };
+    this.ElementNodeFactory.prototype.registerMethod = function(methodName, method) {
+        this[methodName] = method;
+    };
 
     this.TextNodeFactory = function() {
         smartxml.TextNode.apply(this, arguments);
@@ -181,6 +184,9 @@ var WLXMLDocument = function(xml, options) {
     this.TextNodeFactory.prototype.registerTransformation = function(Transformation) {
         return this.transformations.register(Transformation);
     };
+    this.TextNodeFactory.prototype.registerMethod = function(methodName, method) {
+        this[methodName] = method;
+    };
 
     this.classMethods = {};
     this.classTransformations = {};
@@ -279,6 +285,10 @@ $.extend(WLXMLDocument.prototype, {
         this.trigger('contentSet');
     },
 
+    registerMethod: function(methodName, method) {
+        this[methodName] = method;
+    },
+
     registerTransformation: function(Transformation) {
         return this.transformations.register(Transformation);
     },
@@ -328,7 +338,7 @@ $.extend(WLXMLDocument.prototype, {
                             );
                         }
                         targets.forEach(function(target) {
-                            target[methodName] = method;
+                            target.registerMethod(methodName, method)
                         });
                     });
                 }