Author: reebalazs
Date: Sun Dec 30 13:59:57 2007
New Revision: 50198

Modified:
   kukit/kukit.js/branch/finish-closures/kukit/eventreg.js
Log:
Attempt to fix the handling of binder classes
dquote> This is the correct implementation of one of the possible solutions.
dquote> This satisfies the binderclass demo.

Modified: kukit/kukit.js/branch/finish-closures/kukit/eventreg.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/eventreg.js     (original)
+++ kukit/kukit.js/branch/finish-closures/kukit/eventreg.js     Sun Dec 30 
13:59:57 2007
@@ -50,24 +50,40 @@
 
 /* binder registration */
 
-this.registerBinder = function(className, klass) {
+this.registerBinder = function(klass) {
     if (typeof(klass) == 'undefined') {
 ;;;     kukit.E = 'klass argument is mandatory when registering an event';
 ;;;     kukit.E += ' binder (_EventRegistry.registerBinder).';
         throw new Error(kukit.E);
     }
-    if (this.classes[className]) {
-        // Do not allow redefinition
-;;;     var msg = 'Error : event class [' + className + '] already 
registered.';
-;;;     kukit.logError(msg);
+    // See if we are set up already?
+    // We make a mark not on the class prototype,
+    // but on the class itself. This will make
+    // sure inherited classes get a distinct class name.
+    if (klass.__decorated_for_kss__) {
         return;
-    
     }
-    klass.prototype = new _EventBinder();
+    // We do _not_ overwrite the class's prototype, since
+    // that destroys any inheritance it has. Our purpose
+    // is to allow any javascript class to function, so
+    // we copy the class's attributes to the prototype.
+    var binder_prototype = new _EventBinder();
+    for (var key in binder_prototype) {
+        klass.prototype[key] = binder_prototype[key];
+    }
+    // Create a className, and register it too.
+    //
+    // The reason to create a __className__ is to provide a
+    // way to lookup the class by a string. This is needed
+    // because dict keys in javascript can only be strings.
+    className = '' + _eventClassCounter;
+    _eventClassCounter += 1;
     klass.prototype.__className__ = className;
-    var newKlass = function() {};
-    newKlass.prototype = new klass();
-    this.classes[className] = newKlass;
+    this.classes[className] = klass;
+    // mark decorated. We store the class there
+    // so we can decide if this class has been
+    // decorated or not.
+    klass.__decorated_for_kss__ = true;
 };
 
 this.existsBinder = function(className) {
@@ -93,15 +109,8 @@
 ;;;     kukit.E = 'Missing arguments when calling [_EventRegistry.register].';
         throw new Error(kukit.E);
     }
-    // Find out the class name. (Not specified now.)
-    var className = klass.prototype.__className__;
-    if (typeof(className) == 'undefined') {
-        // Create a className, and register it too.
-        className = '' + _eventClassCounter;
-        _eventClassCounter += 1;
-        this.registerBinder(className, klass);
-    }
-    var binderKlass = this.getBinderClass(className);
+    // Register and decorate the binder's class.
+    this.registerBinder(klass);
     if (!eventName) {
 ;;;     kukit.E = '[eventName] argument cannot be empty when registering';
 ;;;     kukit.E += ' an event with [_EventRegistry.register].';
@@ -118,19 +127,9 @@
 ;;;     kukit.E += ' an event with [_EventRegistry.register].';
         throw new Error(kukit.E);
     }
-    // check bindMethodName and defaultActionMethodName
-    if (bindMethodName && ! binderKlass.prototype[bindMethodName]) {
-;;;     kukit.E = 'In _EventRegistry.register bind method [' + bindMethodName;
-;;;     kukit.E += '] is undefined for event [' + eventName;
-;;;     kukit.E += '] namespace [' + namespace + '].';
-        throw new Error(kukit.E);
-    }
-    if (defaultActionMethodName && ! 
binderKlass.prototype[defaultActionMethodName]) {
-;;;     kukit.E = 'In _EventRegistry.register default action method [';
-;;;     kukit.E += defaultActionMethodName + '] is undefined for event [';
-;;;     kukit.E += eventName + '] namespace [' + namespace + '].';
-        throw new Error(kukit.E);
-    }
+    // XXX We do not check bindMethodName and defaltActionMethodName
+    // here, because at this point they may be hidden by closure.
+    // 
     // check the iterator.
     if  (! er.getBindIterator(iterName)) {
 ;;;     kukit.E = 'In _EventRegistry.register unknown bind iterator [';
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to