mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
Make sure to schedule draw when calling removeChildren or destroyChildren
This commit is contained in:
parent
e558ec961e
commit
7c1787ca35
@ -83,6 +83,8 @@ export abstract class Container<
|
|||||||
child.remove();
|
child.remove();
|
||||||
});
|
});
|
||||||
this.children = [];
|
this.children = [];
|
||||||
|
// because all children were detached from parent, request draw via container
|
||||||
|
this._requestDraw();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -98,6 +100,8 @@ export abstract class Container<
|
|||||||
child.destroy();
|
child.destroy();
|
||||||
});
|
});
|
||||||
this.children = [];
|
this.children = [];
|
||||||
|
// because all children were detached from parent, request draw via container
|
||||||
|
this._requestDraw();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
abstract _validateAdd(node: Node): void;
|
abstract _validateAdd(node: Node): void;
|
||||||
|
@ -70,6 +70,32 @@ describe('AutoDraw', function () {
|
|||||||
assert.equal(callCount, 1);
|
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 () {
|
it('schedule draw on cache', function () {
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
|
Loading…
Reference in New Issue
Block a user