Permalink
Browse files

Move Attribute's `_protectAttrs()` method to a static utility method.

This moves the protected `_protectAttrs()` method to a static utility
method on `Y.AttributeCore` and `Y.Attribute`.
  • Loading branch information...
1 parent 0546dd9 commit 19ba4d1d939bfab72e2a6213f4fbb085963dce7c @ericf committed Oct 9, 2012
@@ -96,5 +96,16 @@
* @protected
*/
Attribute._ATTR_CFG = Y.AttributeCore._ATTR_CFG.concat(Y.AttributeEvents._ATTR_CFG);
+
+ /**
+ * Utility method to protect an attribute configuration hash, by merging the
+ * entire object and the individual attr config objects.
+ *
+ * @method protectAttrs
+ * @static
+ * @param {Object} attrs A hash of attribute to configuration object pairs.
+ * @return {Object} A protected version of the `attrs` argument.
+ */
+ Attribute.protectAttrs = Y.AttributeCore.protectAttrs;
- Y.Attribute = Attribute;
+ Y.Attribute = Attribute;
@@ -103,6 +103,28 @@
* @protected
*/
AttributeCore._ATTR_CFG = [SETTER, GETTER, VALIDATOR, VALUE, VALUE_FN, WRITE_ONCE, READ_ONLY, LAZY_ADD, BYPASS_PROXY];
+
+ /**
+ * Utility method to protect an attribute configuration hash, by merging the
+ * entire object and the individual attr config objects.
+ *
+ * @method protectAttrs
+ * @static
+ * @param {Object} attrs A hash of attribute to configuration object pairs.
+ * @return {Object} A protected version of the `attrs` argument.
+ */
+ AttributeCore.protectAttrs = function (attrs) {
+ if (attrs) {
+ attrs = Y.merge(attrs);
+ for (var attr in attrs) {
+ if (attrs.hasOwnProperty(attr)) {
+ attrs[attr] = Y.merge(attrs[attr]);
+ }
+ }
+ }
+
+ return attrs;
+ };
AttributeCore.prototype = {
@@ -794,17 +816,7 @@
* @param {Object} attrs A hash of attribute to configuration object pairs.
* @return {Object} A protected version of the attrs argument.
*/
- _protectAttrs : function(attrs) {
- if (attrs) {
- attrs = Y.merge(attrs);
- for (var attr in attrs) {
- if (attrs.hasOwnProperty(attr)) {
- attrs[attr] = Y.merge(attrs[attr]);
- }
- }
- }
- return attrs;
- },
+ _protectAttrs : AttributeCore.protectAttrs,
/**
* Utility method to normalize attribute values. The base implementation
@@ -878,8 +890,8 @@
baseInst = (Base && Y.instanceOf(this, Base)),
baseCoreInst = (!baseInst && BaseCore && Y.instanceOf(this, BaseCore));
- if ( attrs && !baseInst && !baseCoreInst) {
- this.addAttrs(this._protectAttrs(attrs), values, lazy);
+ if (attrs && !baseInst && !baseCoreInst) {
+ this.addAttrs(Y.AttributeCore.protectAttrs(attrs), values, lazy);
}
}
};
@@ -376,7 +376,7 @@ YUI.add('attribute-core-tests', function(Y) {
testProtect : function() {
var h = this.createHost();
- var q = h._protectAttrs(AttrHost.ATTRS);
+ var q = Y.Attribute.protectAttrs(AttrHost.ATTRS);
Y.Assert.areNotSame(AttrHost.ATTRS, q);
Y.Assert.areEqual(Y.dump(AttrHost.ATTRS), Y.dump(q));
@@ -1297,7 +1297,7 @@ YUI.add('attribute-tests', function(Y) {
testProtect : function() {
var h = this.createHost();
- var q = h._protectAttrs(AttrHost.ATTRS);
+ var q = Y.Attribute.protectAttrs(AttrHost.ATTRS);
Y.Assert.areNotSame(AttrHost.ATTRS, q);
Y.Assert.areEqual(Y.dump(AttrHost.ATTRS), Y.dump(q));
View
@@ -121,7 +121,7 @@
* @type Object
* @static
*/
- Base.ATTRS = Y.AttributeCore.prototype._protectAttrs(Y.BaseCore.ATTRS);
+ Base.ATTRS = Y.AttributeCore.protectAttrs(Y.BaseCore.ATTRS);
Y.mix(Base, Y.BaseCore, false, null, 1);
@@ -890,7 +890,7 @@ YUI.add('base-core-tests', function(Y) {
testProtect : function() {
var h = this.createHost();
- var q = h._protectAttrs(AttrHost.ATTRS);
+ var q = Y.Attribute.protectAttrs(AttrHost.ATTRS);
Y.Assert.areNotSame(AttrHost.ATTRS, q);
Y.Assert.areEqual(Y.dump(AttrHost.ATTRS), Y.dump(q));

0 comments on commit 19ba4d1

Please sign in to comment.