You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by mt...@apache.org on 2007/03/06 19:13:03 UTC

svn commit: r515257 - /incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js

Author: mturyn
Date: Tue Mar  6 11:13:02 2007
New Revision: 515257

URL: http://svn.apache.org/viewvc?view=rev&rev=515257
Log:
1.) Altered getNewAllowedAttributes():
	a.) Removed references to ill-considered superclass() method on bridge instances, which has now been removed.
	b.) Fixed a bug that could make an attribute show up in the list twice.
2.) Moved the attribute mapper creation method from onAttributeSet (called many times, usually) to init() (called once/bridge).

Modified:
    incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js

Modified: incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js?view=diff&rev=515257&r1=515256&r2=515257
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js Tue Mar  6 11:13:02 2007
@@ -108,6 +108,10 @@
  * 
 **/ 
 xap.bridges.basic.AbstractWidgetBridge.prototype.init = function() {
+	if ( !this._getNameToSetterMap()  ){
+		this.initialiseAttributeMaps() ;
+	} //If we needed to initialise the maps.==first use of this bridge class in session
+
 	this.createPeer();
 	
 	if (this.getRootDomNode() && this.getCssStyleName()){
@@ -235,7 +239,7 @@
 		//TODO only add these if user has the event
 		//declared in XML? Would be more efficient
 		//TODO what about bubbling? Report events
-		//on children as our own?
+		//on children as our own?		
 		dojo.event.connect(rootNode,"onfocus", this, "onFocus");
 		dojo.event.connect(rootNode,"onblur", this, "onBlur");
 		dojo.event.connect(rootNode,"ondblclick", this, "onDblClick");
@@ -400,18 +404,10 @@
 	// O.K., this is an attribute we're supposed to handle;
 	// find the function we're supposed to use by looking at
 	// the list the class/constructor keeps:
-	
-	// (Make sure that map's there, first:)
-	
-	//TODO move this to a place where it will get called less often like init?
-	if ( !this._getNameToSetterMap()  ){
-		this.initialiseAttributeMaps() ;
-	} //If we needed to initialise the maps.	
-	
-	
-	// (Subclass calling this method had better have set "constructor" to the class object;
-	// easiest way to ensure this is to use <code>Xap.setupClassAsSubclassOf()</code>
-	// when extending the class from its superclass:)	
+	//(Subclass calling this method had better have set "constructor"
+	//to the class object; easiest way to ensure this is to use
+	//<code>Xap.setupClassAsSubclassOf()</code> or <code>dojo.inherits</code>
+	//when extending the class from its superclass.)
 	var setterFunction = this.getSetterFunctionForAttribute(name) ;
 	
 	// This is our convention:  the setter on the bridge will take this object, the name, and the value:
@@ -465,18 +461,32 @@
 
 
 xap.bridges.basic.AbstractWidgetBridge.prototype.getAllowedAttributes = function(){
-	if (this.constructor._allowedAttributes){
-		return this.constructor._allowedAttributes;
+	// We need this to be an instance method to make it automatically
+	// heritable, but we're actually doing everything on the class/constructor:
+	var theClass = this.constructor ;
+	var theSuperclass = theClass.superclass ;
+	// Memoise; this shouldn't change over the course of a session:
+	if (theClass._allowedAttributes){
+		return theClass._allowedAttributes;
 	}
 	else{
-		var allowedAttributes = [];
-		allowedAttributes = allowedAttributes.concat(this.getNewAllowedAttributes());
-		if (this.superclass && this.superclass()
-				&& this.superclass().getAllowedAttributes
-	 	){		
-			allowedAttributes = allowedAttributes.concat(this.superclass().getAllowedAttributes());
+		var allowedAttributes = [] ;
+		// Method can result in multiple instances of an attribute as follows:
+		// If current instance doesn't implement getNewAllowedAttributes(),
+		// calling "its" method and then the superclass' method means the
+		// superclass method is called twice:		
+		if( this.getNewAllowedAttributes != theSuperclass.getNewAllowedAttributes){
+			allowedAttributes = this.getNewAllowedAttributes() ;
 		}
-		this.constructor._allowedAttributes = allowedAttributes;
+		if (theSuperclass
+				&& theSuperclass && theSuperclass.getAllowedAttributes
+	 	){	
+			allowedAttributes = allowedAttributes.concat(theSuperclass.getAllowedAttributes());
+		}
+		
+		// Set the member, sorting to make this (and other methods?)
+		// much easier to debug:
+		theClass._allowedAttributes = allowedAttributes.sort() ;
 		return allowedAttributes;
 	}