State.js revision 0ba258e972f368be0d5b6271dc025e0db3b22291
/**
* The State class maintains state for a collection of named items, with
* a varying number of properties defined.
*
* It avoids the need to create a separate class for the item, and separate instances
* of these classes for each item, by storing the state in a 2 level hash table,
* improving performance when the number of items is likely to be large.
*
* @constructor
* @class State
*/
Y.State = function() {
/**
* Hash of attributes
* @property data
*/
this.data = {};
};
/**
* Adds a property to an item.
*
* @method add
* @param name {String} The name of the item.
* @param key {String} The name of the property.
* @param val {Any} The value of the property.
*/
var d = this.data;
},
/**
* Adds multiple properties to an item.
*
* @method addAll
* @param name {String} The name of the item.
*/
var key;
for (key in o) {
if (o.hasOwnProperty(key)) {
}
}
},
/**
* Removes a property from an item.
*
* @method remove
* @param name {String} The name of the item.
* @param key {String} The property to remove.
*/
var d = this.data;
}
},
/**
* Removes multiple properties from an item, or remove the item completely.
*
* @method removeAll
* @param name {String} The name of the item.
* @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) {
} else {
}
}, this);
},
/**
* For a given item, returns the value of the property requested, or undefined if not found.
*
* @method get
* @param name {String} The name of the item
* @param key {String} Optional. The property value to retrieve.
* @return {Any} The value of the supplied property.
*/
var d = this.data;
},
/**
* For the given item, returns a disposable object with all of the
*
* @method getAll
* @param name {String} The name of the item
*/
var d = this.data, o;
Y.each(d, function(v, k) {
if (name in d[k]) {
o = o || {};
o[k] = v[name];
}
}, this);
return o;
}
};