Permalink
Browse files

Deprecate AttributeComplex and move its overrides into AttributeCore.

  • Loading branch information...
ericf committed Oct 10, 2012
1 parent 8ced7fd commit b346ca0a3557d1830548d26a9a4bf4ede1eb9d39
Showing with 92 additions and 111 deletions.
  1. +76 −19 src/attribute/js/AttributeCore.js
  2. +1 −0 src/attribute/js/AttributeEvents.js
  3. +15 −92 src/attribute/js/ComplexAttribute.js
@@ -821,22 +821,52 @@
* @protected
* @param {Object} attrs A hash of attribute to configuration object pairs.
* @return {Object} A protected version of the attrs argument.
+ * @deprecated Use `AttributeCore.protectAttrs()` or
+ * `Attribute.protectAttrs()` which are the same static utility method.
*/
_protectAttrs : AttributeCore.protectAttrs,
/**
- * Utility method to normalize attribute values. The base implementation
- * simply merges the hash to protect the original.
+ * Utility method to split out simple attribute name/value pairs ("x")
+ * from complex attribute name/value pairs ("x.y.z"), so that complex
+ * attributes can be keyed by the top level attribute name.
*
* @method _normAttrVals
* @param {Object} valueHash An object with attribute name/value pairs
*
- * @return {Object}
+ * @return {Object} An object literal with 2 properties - "simple" and "complex",
+ * containing simple and complex attribute values respectively keyed
+ * by the top level attribute name, or null, if valueHash is falsey.
*
* @private
*/
_normAttrVals : function(valueHash) {
- return (valueHash) ? Y.merge(valueHash) : null;
+ var vals = {},
+ subvals = {},
+ path,
+ attr,
+ v, k;
+
+ if (valueHash) {
+ for (k in valueHash) {
+ if (valueHash.hasOwnProperty(k)) {
+ if (k.indexOf(DOT) !== -1) {
+ path = k.split(DOT);
+ attr = path.shift();
+ v = subvals[attr] = subvals[attr] || [];
+ v[v.length] = {
+ path : path,
+ value: valueHash[k]
+ };
+ } else {
+ vals[k] = valueHash[k];
+ }
+ }
+ }
+ return { simple:vals, complex:subvals };
+ } else {
+ return null;
+ }
},
/**
@@ -855,25 +885,52 @@
* @private
*/
_getAttrInitVal : function(attr, cfg, initValues) {
- var val, valFn;
- // init value is provided by the user if it exists, else, provided by the config
- if (!cfg.readOnly && initValues && initValues.hasOwnProperty(attr)) {
- val = initValues[attr];
- } else {
- val = cfg.value;
- valFn = cfg.valueFn;
-
+
+ var val = cfg.value,
+ valFn = cfg.valueFn,
+ tmpVal,
+ initValSet = false,
+ simple,
+ complex,
+ i,
+ l,
+ path,
+ subval,
+ subvals;
+
+ if (!cfg.readOnly && initValues) {
+ // Simple Attributes
+ simple = initValues.simple;
+ if (simple && simple.hasOwnProperty(attr)) {
+ val = simple[attr];
+ initValSet = true;
+ }
+ }
+
+ if (valFn && !initValSet) {
+ if (!valFn.call) {
+ valFn = this[valFn];
+ }
if (valFn) {
- if (!valFn.call) {
- valFn = this[valFn];
- }
- if (valFn) {
- val = valFn.call(this, attr);
- }
+ tmpVal = valFn.call(this, attr);
+ val = tmpVal;
}
}
- Y.log('initValue for ' + attr + ':' + val, 'info', 'attribute');
+ if (!cfg.readOnly && initValues) {
+
+ // Complex Attributes (complex values applied, after simple, in case both are set)
+ complex = initValues.complex;
+
+ if (complex && complex.hasOwnProperty(attr) && (val !== undefined) && (val !== null)) {
+ subvals = complex[attr];
+ for (i = 0, l = subvals.length; i < l; ++i) {
+ path = subvals[i].path;
+ subval = subvals[i].value;
+ O.setValue(val, path, subval);
+ }
+ }
+ }
return val;
},
@@ -31,6 +31,7 @@
function AttributeEvents() {
// Perf tweak - avoid creating event literals if not required.
this._ATTR_E_FACADE = {};
+
EventTarget.call(this, {emitFacade:true});
}
@@ -4,61 +4,34 @@
* @module attribute
* @submodule attribute-complex
* @for Attribute
+ * @deprecated AttributeComplex's overrides are now part of AttributeCore.
*/
- var O = Y.Object,
- DOT = ".";
-
- Y.Attribute.Complex = function() {};
- Y.Attribute.Complex.prototype = {
+ var Attribute = Y.Attribute;
+ Attribute.Complex = function() {};
+ Attribute.Complex.prototype = {
+
/**
- * Utility method to split out simple attribute name/value pairs ("x")
+ * Utility method to split out simple attribute name/value pairs ("x")
* from complex attribute name/value pairs ("x.y.z"), so that complex
* attributes can be keyed by the top level attribute name.
*
* @method _normAttrVals
* @param {Object} valueHash An object with attribute name/value pairs
*
* @return {Object} An object literal with 2 properties - "simple" and "complex",
- * containing simple and complex attribute values respectively keyed
+ * containing simple and complex attribute values respectively keyed
* by the top level attribute name, or null, if valueHash is falsey.
*
* @private
*/
- _normAttrVals : function(valueHash) {
- var vals = {},
- subvals = {},
- path,
- attr,
- v, k;
-
- if (valueHash) {
- for (k in valueHash) {
- if (valueHash.hasOwnProperty(k)) {
- if (k.indexOf(DOT) !== -1) {
- path = k.split(DOT);
- attr = path.shift();
- v = subvals[attr] = subvals[attr] || [];
- v[v.length] = {
- path : path,
- value: valueHash[k]
- };
- } else {
- vals[k] = valueHash[k];
- }
- }
- }
- return { simple:vals, complex:subvals };
- } else {
- return null;
- }
- },
-
+ _normAttrVals : Attribute.prototype._normAttrVals,
+
/**
* Returns the initial value of the given attribute from
- * either the default configuration provided, or the
- * over-ridden value if it exists in the set of initValues
+ * either the default configuration provided, or the
+ * over-ridden value if it exists in the set of initValues
* provided and the attribute is not read-only.
*
* @param {String} attr The name of the attribute
@@ -70,59 +43,9 @@
* @method _getAttrInitVal
* @private
*/
- _getAttrInitVal : function(attr, cfg, initValues) {
-
- var val = cfg.value,
- valFn = cfg.valueFn,
- tmpVal,
- initValSet = false,
- simple,
- complex,
- i,
- l,
- path,
- subval,
- subvals;
-
- if (!cfg.readOnly && initValues) {
- // Simple Attributes
- simple = initValues.simple;
- if (simple && simple.hasOwnProperty(attr)) {
- val = simple[attr];
- initValSet = true;
- }
- }
-
- if (valFn && !initValSet) {
- if (!valFn.call) {
- valFn = this[valFn];
- }
- if (valFn) {
- tmpVal = valFn.call(this, attr);
- val = tmpVal;
- }
- }
-
- if (!cfg.readOnly && initValues) {
-
- // Complex Attributes (complex values applied, after simple, in case both are set)
- complex = initValues.complex;
-
- if (complex && complex.hasOwnProperty(attr) && (val !== undefined) && (val !== null)) {
- subvals = complex[attr];
- for (i = 0, l = subvals.length; i < l; ++i) {
- path = subvals[i].path;
- subval = subvals[i].value;
- O.setValue(val, path, subval);
- }
- }
- }
-
- return val;
- }
+ _getAttrInitVal : Attribute.prototype._getAttrInitVal
+
};
- Y.mix(Y.Attribute, Y.Attribute.Complex, true, null, 1);
-
- // Consistency with the rest of the Attribute addons for now.
- Y.AttributeComplex = Y.Attribute.Complex;
+ // Consistency with the rest of the Attribute addons for now.
+ Y.AttributeComplex = Attribute.Complex;

0 comments on commit b346ca0

Please sign in to comment.