[REF] web: don't destroy twice a widget's children
Widget class indirectly inherits from ParentedMixin (through PropertiesMixin). The Widget's children are destroyed in both the ParentedMixin and the Widget's own destroy() method. This commit prevents from trying to destroy already destroyed children and specifically from looping again on those children (resulting into a minor performance improvement). closes odoo/odoo#32174 Signed-off-by: Adrien Dieudonné (adr) <adr@odoo.com>
This commit is contained in:
@@ -98,8 +98,8 @@ var ParentedMixin = {
|
||||
* resource it could have reserved.
|
||||
*/
|
||||
destroy : function () {
|
||||
_.each(this.getChildren(), function (el) {
|
||||
el.destroy();
|
||||
this.getChildren().forEach(function (child) {
|
||||
child.destroy();
|
||||
});
|
||||
this.setParent(undefined);
|
||||
this.__parentedDestroyed = true;
|
||||
|
||||
@@ -172,13 +172,10 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, {
|
||||
* destroying itself.
|
||||
*/
|
||||
destroy: function () {
|
||||
this.getChildren().forEach(function (child) {
|
||||
child.destroy();
|
||||
});
|
||||
mixins.PropertiesMixin.destroy.call(this);
|
||||
if (this.$el) {
|
||||
this.$el.remove();
|
||||
}
|
||||
mixins.PropertiesMixin.destroy.call(this);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -468,6 +468,20 @@ QUnit.module('core', {}, function () {
|
||||
slowWillStartPromise.resolve();
|
||||
});
|
||||
|
||||
QUnit.test("don't destroy twice widget's children", function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var parent = new Widget();
|
||||
var child = new (Widget.extend({
|
||||
destroy: function () {
|
||||
assert.step('destroy');
|
||||
}
|
||||
}))(parent);
|
||||
|
||||
parent.destroy();
|
||||
assert.verifySteps(['destroy'], "child should have been detroyed only once");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user