PDA

View Full Version : [FIXED][3.0] Ext.Container.removeAll() results in infinite loop



ThorstenSuckow
18 Apr 2009, 5:34 AM
What steps will reproduce the problem?
Create a container and add various components to it. Now add a "beforeremove" listener to the container and return for at least one component "false", which basically tells the container to not remove this component. Now call "removeAll()" on the container.

What is the expected output?
All components except for the one where the "beforeremove" listener returned "false" get removed from the container.

What do you see instead?
The "removeAll()" gets stuck in an infinite loop, due to



removeAll: function(autoDestroy){
this.initItems();
var item, items = [];
while((item = this.items.last())){
items.unshift(this.remove(item, autoDestroy));
}
return items;
},


The condition for the while loop will always equal to true, since "this.items.last()" will reference the component for which the "beforeremove" listener returned "false".

evant
20 Apr 2009, 9:13 AM
Fair enough, try the following patch + test case:



Ext.override(Ext.Container, {
removeAll: function(autoDestroy){
this.initItems();
var item, rem = [], items = [];
this.items.each(function(i){
rem.push(i)
});
for (var i = 0, len = rem.length; i < len; ++i){
item = rem[i];
this.remove(item, autoDestroy);
if(item.ownerCt !== this){
items.push(item);
}
}
return items;
}
});




Ext.onReady(function(){
var tabs = new Ext.TabPanel({
width: 400,
height: 400,
renderTo: document.body,
items: [{
title: 'Item 1'
},{
title: 'Item 2'
},{
title: 'Item 3'
},{
title: 'Item 4'
}],
listeners: {
beforeremove: function(ct, c){
return c.title != 'Item 2';
}
}
});
console.log(tabs.removeAll());
});