Remove singular adding for ve.ui.GroupElement

By making the API for adding/removing/clearing always plural, it greatly
simplifies the interfaces and reduces function call overhead in most
situations.

Change-Id: Ia8f23a373a01a8f6d5081587a591563e4f25ea42
This commit is contained in:
Trevor Parscal 2013-04-29 13:58:58 -07:00 committed by Gerrit Code Review
parent e9346fdb60
commit 52529d790b

View file

@ -41,29 +41,20 @@ ve.ui.GroupElement.prototype.getItems = function () {
* @chainable
*/
ve.ui.GroupElement.prototype.addItems = function ( items ) {
var i, len;
for ( i = 0, len = items.length; i < len; i++ ) {
this.addItem( items[i] );
}
return this;
};
var i, len, item;
/**
* Add item.
*
* @method
* @param {ve.ui.Widget} item Item
* @chainable
*/
ve.ui.GroupElement.prototype.addItem = function ( item ) {
// Check if item exists then remove it first, effectively "moving" it
if ( this.items.indexOf( item ) !== -1 ) {
this.removeItems( [item] );
for ( i = 0, len = items.length; i < len; i++ ) {
item = items[i];
// Check if item exists then remove it first, effectively "moving" it
if ( this.items.indexOf( item ) !== -1 ) {
this.removeItems( [item] );
}
// Add the item
this.items.push( item );
this.$.append( item.$ );
this.$items = this.$items.add( item.$ );
}
// Add the item
this.items.push( item );
this.$.append( item.$ );
this.$items = this.$items.add( item.$ );
return this;
};