From 52529d790b9039df55bcfdbd92e144cc0b62b380 Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Mon, 29 Apr 2013 13:58:58 -0700 Subject: [PATCH] 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 --- modules/ve/ui/elements/ve.ui.GroupElement.js | 33 +++++++------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/modules/ve/ui/elements/ve.ui.GroupElement.js b/modules/ve/ui/elements/ve.ui.GroupElement.js index eec22df000..9a0fed5ea5 100644 --- a/modules/ve/ui/elements/ve.ui.GroupElement.js +++ b/modules/ve/ui/elements/ve.ui.GroupElement.js @@ -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; };