attribute-debug.js revision eaa9719567e2ec55d96f9298077f5fc0effe1ed3
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * The State class maintains state for a collection of named items, with
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * a varying number of properties defined.
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * It avoids the need to create a separate class for the item, and separate instances
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * of these classes for each item, by storing the state in a 2 level hash table,
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * improving performance when the number of items is likely to be large.
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * @constructor
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * @class State
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass Y.State = function() {
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * Hash of attributes
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * @property data
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * Adds a property to an item.
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * @method add
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * @param name {String} The name of the item.
781e495b446a0ea73ac21ece6fa0a2a907da6062Dav Glass * @param key {String} The name of the property.
var d = this.data;
var key;
for (key in o) {
var d = this.data;
* @param o {Object|Array} Collection of properties to delete. If not provided, the entire item is removed.
var d = this.data;
Y.each(o || d, function(v, k) {
var d = this.data;
var d = this.data, o;
Y.each(d, function(v, k) {
if (name in d[k]) {
o[k] = v[name];
MODIFIABLE = {};
* Attribute provides configurable attribute support along with attribute change events. It is designed to be
* augmented onto a host class, and provides the host with the ability to configure attributes to store and retrieve state,
* <p><strong>NOTE:</strong> Most implementations will be better off extending the <a href="Base.html">Base</a> class,
* instead of augmenting Attribute directly. Base augments Attribute and will handle the initial configuration
function Attribute() {
this._ATTR_E_FACADE = {};
* <p>The value to return from an attribute setter in order to prevent the set from going through.</p>
* functionality into a single setter function, which either returns the massaged value to be stored or
Attribute._ATTR_CFG = [SETTER, GETTER, VALIDATOR, VALUE, VALUE_FN, WRITE_ONCE, READ_ONLY, LAZY_ADD, BROADCAST];
* <dd>The setter function used to massage or normalize the value passed to the set method for the attribute.
* <a href="#property_Attribute.INVALID_VALUE">Attribute.INVALID_VALUE</a>, from the setter will prevent
* <dd>The getter function used to massage or normalize the value returned by the get method for the attribute.
* The value returned by the getter function is the value which will be returned to the user when they
* <dd>If and how attribute change events for this attribute should be broadcast. See Event.Custom's <a href="Event.Custom.html#property_broadcast">broadcast</a> property for
* This flag can be used to over-ride lazy initialization on a per attribute basis, when adding multiple attributes through
* <p>The setter, getter and validator are invoked with the value and name passed in as the first and second arguments, and with
* @param {Object} config An object with attribute configuration property/value pairs, specifying the configuration for the attribute.
* <strong>NOTE:</strong> The configuration object is modified when adding an attribute, so if you need
* @param {boolean} lazy (optional) Whether or not to add this attribute lazily (on the first call to get/set).
if (this.attrAdded(name) && !conf.get(name, IS_LAZY_ADD)) { Y.log('Attribute: ' + name + ' already exists. Cannot add it again without removing it first', 'warn', 'attribute'); }
if (config.readOnly && !hasValue) { Y.log('readOnly attribute: ' + name + ', added without an initial value. Value will be set on initial call to set', 'warn', 'attribute');}
if(hasValue) {
if (hasValue) {
// Go through set, so that raw values get normalized/validated
* @return {boolean} true if an attribute with the given name has been added, false if it hasn't. This method will return true for lazily added attributes.
* @param {Object} config An object with configuration property/value pairs, specifying the configuration properties to modify.
if (!this.attrAdded(name)) {Y.log('Attribute modifyAttr:' + name + ' has not been added. Use addAttr to add the attribute', 'warn', 'attribute');}
* dot notation can be used to obtain the value of a property of the object (e.g. <code>get("x.y.z")</code>)
path,
val;
var cfg = {};
return val;
* @param {String} name Optional. The name of the attribute to reset. If omitted, all attributes are reset.
if (name) {
this.reset(n);
* Allows setting of readOnly/writeOnce attributes. See <a href="#method_set">set</a> for argument details.
var allowSet = true,
path,
allowSet = false;
allowSet = false;
if (allowSet) {
if (path) {
allowSet = false;
if (allowSet) {
* @param {Object} opts Any additional event data to mix into the attribute change event's event facade.
queuable:false,
silent:true,
_defAttrChangeFn : function(e) {
Y.log('State not updated and stopImmediatePropagation called for attribute: ' + e.attrName + ' , value:' + e.newVal, 'warn', 'attribute');
* @param {String} subAttrName The sub-attribute name, if setting a sub-attribute property ("x.y.z").
var allowSet = true,
if (validator) {
if (setter) {
Y.log('Attribute: ' + attrName + ', setter returned Attribute.INVALID_VALUE for value:' + newVal, 'warn', 'attribute');
allowSet = false;
Y.log('Attribute: ' + attrName + ', raw value: ' + newVal + ' modified by setter to:' + retVal, 'info', 'attribute');
if (allowSet) {
allowSet = false;
allowSet = false;
return allowSet;
* @param {Array | boolean} attrs Optional. An array of attribute names. If omitted, all attribute values are
// Go through get, to honor cloning/normalization
* @param {Object} cfgs An object with attribute name/configuration pairs.
* @param {Object} values An object with attribute name/value pairs, defining the initial values to apply.
* Values defined in the cfgs argument will be over-written by values in this argument unless defined as read only.
* @param {boolean} lazy Whether or not to delay the intialization of these attributes until the first call to get/set.
* Individual attributes can over-ride this behavior by defining a lazyAdd configuration property in their configuration.
if (cfgs) {
* @param {Object} cfgs An object with attribute name/configuration pairs.
* @param {Object} values An object with attribute name/value pairs, defining the initial values to apply.
* Values defined in the cfgs argument will be over-written by values in this argument unless defined as read only.
* @param {boolean} lazy Whether or not to delay the intialization of these attributes until the first call to get/set.
* Individual attributes can over-ride this behavior by defining a lazyAdd configuration property in their configuration.
var attr,
var vals = {},
subvals = {},
path,
attr,
if (valueHash) {
for (k in valueHash) {
v[v.length] = {
* @param {Object} initValues The object with simple and complex attribute name/value pairs returned from _splitAttrVals
path,
return val;