Merge pull request #1140 from AlbertBrand/fix/batch-draw-after-remove-children

Make sure to schedule draw when calling removeChildren/destroyChildren
This commit is contained in:
Anton Lavrenov 2021-06-30 05:36:26 -05:00 committed by GitHub
commit c4937c46ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -83,6 +83,8 @@ export abstract class Container<
child.remove();
});
this.children = [];
// because all children were detached from parent, request draw via container
this._requestDraw();
return this;
}
/**
@ -98,6 +100,8 @@ export abstract class Container<
child.destroy();
});
this.children = [];
// because all children were detached from parent, request draw via container
this._requestDraw();
return this;
}
abstract _validateAdd(node: Node): void;

View File

@ -70,6 +70,32 @@ describe('AutoDraw', function () {
assert.equal(callCount, 1);
});
// ======================================================
it('schedules draw when calling removeChildren/destroyChildren', () => {
var stage = addStage();
var layer = new Konva.Layer();
var group1 = new Konva.Group();
var group2 = new Konva.Group();
stage.add(layer);
layer.add(group1);
group1.add(new Konva.Circle());
layer.add(group2);
group2.add(new Konva.Circle());
let callCount = 0;
layer.batchDraw = function () {
callCount += 1;
Konva.Layer.prototype.batchDraw.call(this);
return layer;
};
group1.destroyChildren();
assert.equal(callCount, 1);
group2.removeChildren();
assert.equal(callCount, 2);
});
// ======================================================
it('schedule draw on cache', function () {
var stage = addStage();