mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 06:55:17 +08:00
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:
commit
c4937c46ba
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user