mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
Faster removeChildren
and destroyChildren
methods
This commit is contained in:
parent
74060ce935
commit
3a5b6eb766
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@ node_modules
|
|||||||
bower_components
|
bower_components
|
||||||
phantomjs.exe
|
phantomjs.exe
|
||||||
documentation
|
documentation
|
||||||
|
test/sandbox.html
|
||||||
|
|
||||||
# Numerous always-ignore extensions
|
# Numerous always-ignore extensions
|
||||||
*.diff
|
*.diff
|
||||||
|
@ -27,17 +27,20 @@
|
|||||||
* @memberof Kinetic.Container.prototype
|
* @memberof Kinetic.Container.prototype
|
||||||
*/
|
*/
|
||||||
removeChildren: function() {
|
removeChildren: function() {
|
||||||
var children = this.children,
|
var children = Kinetic.Collection.toCollection(this.children);
|
||||||
child;
|
var child;
|
||||||
|
for (var i = 0; i < children.length; i++) {
|
||||||
while(children.length > 0) {
|
child = children[i];
|
||||||
child = children[0];
|
// reset parent to prevent many _setChildrenIndices calls
|
||||||
|
delete child.parent;
|
||||||
|
child.index = 0;
|
||||||
if (child.hasChildren()) {
|
if (child.hasChildren()) {
|
||||||
child.removeChildren();
|
child.removeChildren();
|
||||||
}
|
}
|
||||||
child.remove();
|
child.remove();
|
||||||
}
|
}
|
||||||
|
children = null;
|
||||||
|
this.children = new Kinetic.Collection();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -46,10 +49,17 @@
|
|||||||
* @memberof Kinetic.Container.prototype
|
* @memberof Kinetic.Container.prototype
|
||||||
*/
|
*/
|
||||||
destroyChildren: function() {
|
destroyChildren: function() {
|
||||||
var children = this.children;
|
var children = Kinetic.Collection.toCollection(this.children);
|
||||||
while(children.length > 0) {
|
var child;
|
||||||
children[0].destroy();
|
for (var i = 0; i < children.length; i++) {
|
||||||
|
child = children[i];
|
||||||
|
// reset parent to prevent many _setChildrenIndices calls
|
||||||
|
delete child.parent;
|
||||||
|
child.index = 0;
|
||||||
|
child.destroy();
|
||||||
}
|
}
|
||||||
|
children = null;
|
||||||
|
this.children = new Kinetic.Collection();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>KineticJS Mocha Tests</title>
|
|
||||||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
|
|
||||||
<style>
|
|
||||||
#mocha .test {
|
|
||||||
overflow: auto;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="mocha"></div>
|
|
||||||
|
|
||||||
<!-- used for KineticJS container -->
|
|
||||||
<div id="container"></div>
|
|
||||||
|
|
||||||
<script src="../node_modules/mocha/mocha.js"></script>
|
|
||||||
<script src="../node_modules/chai/chai.js"></script>
|
|
||||||
<script src="../dist/kinetic-dev.js"></script>
|
|
||||||
<script>
|
|
||||||
Kinetic.enableTrace = true;
|
|
||||||
|
|
||||||
var stage = new Kinetic.Stage({
|
|
||||||
container: 'container',
|
|
||||||
width: 578,
|
|
||||||
height: 200
|
|
||||||
});
|
|
||||||
var layer = new Kinetic.Layer();
|
|
||||||
|
|
||||||
var text = new Kinetic.Text({
|
|
||||||
x: 10,
|
|
||||||
y: 10,
|
|
||||||
//stroke: '#555',
|
|
||||||
//strokeWidth: 5,
|
|
||||||
text: 'HEADING\n\nAll the world\'s a stage, and all the men and women merely players. They have their exits and their entrances; And one man in his time plays many parts.',
|
|
||||||
//text: 'HEADING\n\nThis is a really cool paragraph. \n And this is a footer.',
|
|
||||||
fontSize: 16,
|
|
||||||
fontFamily: 'Calibri',
|
|
||||||
fontStyle: 'normal',
|
|
||||||
fill: '#555',
|
|
||||||
//width: 20,
|
|
||||||
width: 380,
|
|
||||||
//width: 200,
|
|
||||||
padding: 20,
|
|
||||||
align: 'center',
|
|
||||||
shadowColor: 'red',
|
|
||||||
shadowBlur: 1,
|
|
||||||
shadowOffset: [10, 10],
|
|
||||||
shadowOpacity: 0.5,
|
|
||||||
draggable: true
|
|
||||||
});
|
|
||||||
|
|
||||||
layer.add(text);
|
|
||||||
stage.add(layer);
|
|
||||||
|
|
||||||
console.log(layer.getContext().getTrace());
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user