Update of /cvsroot/qooxdoo/qooxdoo/source/script/core
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11758/source/script/core
Modified Files:
Tag: renderer
QxExtend.js
Log Message:
Use lightweight setter for many properties
Index: QxExtend.js
===================================================================
RCS file: /cvsroot/qooxdoo/qooxdoo/source/script/core/QxExtend.js,v
retrieving revision 1.7.2.104
retrieving revision 1.7.2.105
diff -u -d -r1.7.2.104 -r1.7.2.105
--- QxExtend.js 23 Jan 2006 15:17:13 -0000 1.7.2.104
+++ QxExtend.js 23 Jan 2006 15:26:26 -0000 1.7.2.105
@@ -451,129 +451,211 @@
pp[QxConst.INTERNAL_TOGGLE + p.method] = function(newValue) {
return this[QxConst.INTERNAL_SET + p.method](!this[valueKey]);
};
- };
-
- // building setFoo(): Setup new value, do type and change detection, converting types, call unit detection, ...
- pp[QxConst.INTERNAL_SET + p.method] = function(newValue)
+ };
+
+ if (p.allowMultipleArguments || p.hasConvert || p.hasInstance || p.hasClassName || p.hasPossibleValues || p.hasUnitDetection || p.addToQueue || p.addToQueueRuntime || p.addToStateQueue)
{
- // convert multiple arguments to array
- if (p.allowMultipleArguments && arguments.length > 1) {
- newValue = QxUtil.convertArgumentsToArray(arguments);
- };
-
- // support converter methods
- if (p.hasConvert)
+ // building setFoo(): Setup new value, do type and change detection, converting types, call unit detection, ...
+ pp[QxConst.INTERNAL_SET + p.method] = function(newValue)
{
- try
- {
- newValue = p.convert.call(this, newValue, p);
- }
- catch(ex)
+ // convert multiple arguments to array
+ if (p.allowMultipleArguments && arguments.length > 1) {
+ newValue = QxUtil.convertArgumentsToArray(arguments);
+ };
+
+ // support converter methods
+ if (p.hasConvert)
{
- throw new Error("Attention! Could not convert new value for " + p.name + ": " + newValue + ": " + ex);
+ try
+ {
+ newValue = p.convert.call(this, newValue, p);
+ }
+ catch(ex)
+ {
+ throw new Error("Attention! Could not convert new value for " + p.name + ": " + newValue + ": " + ex);
+ };
};
- };
-
- var oldValue = this[valueKey];
-
- if (newValue == oldValue) {
- return newValue;
- };
- if (!(newValue == null && p.allowNull))
- {
- if (p.hasType && typeof newValue != p.type) {
- return this.error("Attention! The value \"" + newValue + "\" is an invalid value for the property \"" + p.name + "\" which must be typeof \"" + p.type + "\" but is typeof \"" + typeof newValue + "\"!", QxConst.INTERNAL_SET + p.method);
- };
-
- if (p.hasInstance && !(newValue instanceof QxClasses[p.instance])) {
- return this.error("Attention! The value \"" + newValue + "\" is an invalid value for the property \"" + p.name + "\" which must be an instance of \"" + p.instance + "\"!", QxConst.INTERNAL_SET + p.method);
+ var oldValue = this[valueKey];
+
+ if (newValue == oldValue) {
+ return newValue;
};
-
- if (p.hasClassName && newValue.classname != p.classname) {
- return this.error("Attention! The value \"" + newValue + "\" is an invalid value for the property \"" + p.name + "\" which must be an object with the classname \"" + p.classname + "\"!", QxConst.INTERNAL_SET + p.method);
+
+ if (!(newValue == null && p.allowNull))
+ {
+ if (p.hasType && typeof newValue != p.type) {
+ return this.error("Attention! The value \"" + newValue + "\" is an invalid value for the property \"" + p.name + "\" which must be typeof \"" + p.type + "\" but is typeof \"" + typeof newValue + "\"!", QxConst.INTERNAL_SET + p.method);
+ };
+
+ if (p.hasInstance && !(newValue instanceof QxClasses[p.instance])) {
+ return this.error("Attention! The value \"" + newValue + "\" is an invalid value for the property \"" + p.name + "\" which must be an instance of \"" + p.instance + "\"!", QxConst.INTERNAL_SET + p.method);
+ };
+
+ if (p.hasClassName && newValue.classname != p.classname) {
+ return this.error("Attention! The value \"" + newValue + "\" is an invalid value for the property \"" + p.name + "\" which must be an object with the classname \"" + p.classname + "\"!", QxConst.INTERNAL_SET + p.method);
+ };
+
+ if (p.hasPossibleValues && newValue != null && !p.possibleValues.contains(newValue)) {
+ return this.error("Failed to save value for " + p.name + ". '" + newValue + "' is not a possible value!", QxConst.INTERNAL_SET + p.method);
+ };
};
-
- if (p.hasPossibleValues && newValue != null && !p.possibleValues.contains(newValue)) {
- return this.error("Failed to save value for " + p.name + ". '" + newValue + "' is not a possible value!", QxConst.INTERNAL_SET + p.method);
+
+ // Allow to check and transform the new value before storage
+ if (typeof this[checkKey] == QxConst.TYPEOF_FUNCTION)
+ {
+ try
+ {
+ newValue = this[checkKey](newValue, p);
+
+ // Don't do anything if new value is indentical to old value
+ if (newValue == oldValue) {
+ return newValue;
+ };
+ }
+ catch(ex)
+ {
+ return this.error("Failed to check property " + p.name + ": " + ex, checkKey);
+ };
};
- };
-
- // Allow to check and transform the new value before storage
- if (typeof this[checkKey] == QxConst.TYPEOF_FUNCTION)
- {
- try
+
+ // Store new value
+ this[valueKey] = newValue;
+
+ // Check if there is a modifier implementation
+ if (typeof this[modifyKey] == QxConst.TYPEOF_FUNCTION)
{
- newValue = this[checkKey](newValue, p);
-
- // Don't do anything if new value is indentical to old value
- if (newValue == oldValue) {
- return newValue;
- };
+ try
+ {
+ var r = this[modifyKey](newValue, oldValue, p);
+ if (!r) {
+ return this.error("Modification of property \"" + p.name + "\" failed without exception (" + r + ")", modifyKey);
+ };
+ }
+ catch(ex)
+ {
+ return this.error("Modification of property \"" + p.name + "\" failed with exception (" + ex + ")", modifyKey);
+ };
+ };
+
+ // Unit detection support
+ if (p.hasUnitDetection) {
+ this[unitDetectionKey](p, newValue);
+ };
+
+ // Auto queue addition support
+ if (p.addToQueue) {
+ this.addToQueue(p.name);
}
- catch(ex)
+ else if (p.addToQueueRuntime) {
+ this.addToQueueRuntime(p.name);
+ };
+
+ // Auto state queue addition support
+ if (p.addToStateQueue) {
+ this._addToGlobalStateQueue();
+ };
+
+ // Create Event
+ if (this.hasEventListeners && this.hasEventListeners(changeKey))
{
- return this.error("Failed to check property " + p.name + ": " + ex, checkKey);
+ var ce = new QxDataEvent(changeKey, newValue, oldValue, false);
+
+ ce.setTarget(this);
+
+ try
+ {
+ this.dispatchEvent(ce, true);
+ }
+ catch(ex)
+ {
+ throw new Error("Property " + p.name + " modified: Failed to dispatch change event: " + ex);
+ };
+
+ ce = null;
};
+
+ return newValue;
};
-
- // Store new value
- this[valueKey] = newValue;
-
- // Check if there is a modifier implementation
- if (typeof this[modifyKey] == QxConst.TYPEOF_FUNCTION)
+ }
+ else
+ {
+ // building setFoo(): Setup new value, do type and change detection, converting types, call unit detection, ...
+ pp[QxConst.INTERNAL_SET + p.method] = function(newValue)
{
- try
+ // this.debug("Fast Setter: " + p.name);
+
+ var oldValue = this[valueKey];
+
+ if (newValue == oldValue) {
+ return newValue;
+ };
+
+ if (!(newValue == null && p.allowNull))
{
- var r = this[modifyKey](newValue, oldValue, p);
- if (!r) {
- return this.error("Modification of property \"" + p.name + "\" failed without exception (" + r + ")", modifyKey);
+ if (p.hasType && typeof newValue != p.type) {
+ return this.error("Attention! The value \"" + newValue + "\" is an invalid value for the property \"" + p.name + "\" which must be typeof \"" + p.type + "\" but is typeof \"" + typeof newValue + "\"!", QxConst.INTERNAL_SET + p.method);
};
- }
- catch(ex)
+ };
+
+ // Allow to check and transform the new value before storage
+ if (typeof this[checkKey] == QxConst.TYPEOF_FUNCTION)
{
- return this.error("Modification of property \"" + p.name + "\" failed with exception (" + ex + ")", modifyKey);
+ try
+ {
+ newValue = this[checkKey](newValue, p);
+
+ // Don't do anything if new value is indentical to old value
+ if (newValue == oldValue) {
+ return newValue;
+ };
+ }
+ catch(ex)
+ {
+ return this.error("Failed to check property " + p.name + ": " + ex, checkKey);
+ };
};
- };
-
- // Unit detection support
- if (p.hasUnitDetection) {
- this[unitDetectionKey](p, newValue);
- };
-
- // Auto queue addition support
- if (p.addToQueue) {
- this.addToQueue(p.name);
- }
- else if (p.addToQueueRuntime) {
- this.addToQueueRuntime(p.name);
- };
-
- // Auto state queue addition support
- if (p.addToStateQueue) {
- this._addToGlobalStateQueue();
- };
-
- // Create Event
- if (this instanceof QxTarget && this.hasEventListeners(changeKey))
- {
- var ce = new QxDataEvent(changeKey, newValue, oldValue, false);
-
- ce.setTarget(this);
-
- try
+
+ // Store new value
+ this[valueKey] = newValue;
+
+ // Check if there is a modifier implementation
+ if (typeof this[modifyKey] == QxConst.TYPEOF_FUNCTION)
{
- this.dispatchEvent(ce, true);
- }
- catch(ex)
+ try
+ {
+ var r = this[modifyKey](newValue, oldValue, p);
+ if (!r) {
+ return this.error("Modification of property \"" + p.name + "\" failed without exception (" + r + ")", modifyKey);
+ };
+ }
+ catch(ex)
+ {
+ return this.error("Modification of property \"" + p.name + "\" failed with exception (" + ex + ")", modifyKey);
+ };
+ };
+
+ // Create Event
+ if (this.hasEventListeners && this.hasEventListeners(changeKey))
{
- throw new Error("Property " + p.name + " modified: Failed to dispatch change event: " + ex);
+ var ce = new QxDataEvent(changeKey, newValue, oldValue, false);
+
+ ce.setTarget(this);
+
+ try
+ {
+ this.dispatchEvent(ce, true);
+ }
+ catch(ex)
+ {
+ throw new Error("Property " + p.name + " modified: Failed to dispatch change event: " + ex);
+ };
+
+ ce = null;
};
-
- ce = null;
- };
-
- return newValue;
+
+ return newValue;
+ };
};
// building user configured get alias for property
|