mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 18:27:58 +08:00
ids and names hashes used for node selection via get() has moved to Global in order to greatly simplify the selection logic. This means that node ids and names are shared across all stages. If two stages each have a node with the same id, only the last id set will be accessibile (similar to DOM)
This commit is contained in:
@@ -236,7 +236,7 @@ Test.Modules.CONTAINER = {
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
id: 'myCircle'
|
||||
id: 'myCircle3'
|
||||
});
|
||||
|
||||
var rect = new Kinetic.Rect({
|
||||
@@ -247,23 +247,25 @@ Test.Modules.CONTAINER = {
|
||||
fill: 'purple',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
name: 'myRect'
|
||||
name: 'myRect3'
|
||||
});
|
||||
|
||||
layer.add(circle);
|
||||
layer.add(rect);
|
||||
stage.add(layer);
|
||||
|
||||
var go = Kinetic.Global;
|
||||
|
||||
test(stage.ids['myCircle'].getId() === 'myCircle', 'circle id not in ids hash');
|
||||
test(stage.names['myRect'][0].getName() === 'myRect', 'rect name not in names hash');
|
||||
test(go.ids['myCircle3'].getId() === 'myCircle3', 'circle id not in ids hash');
|
||||
test(go.names['myRect3'][0].getName() === 'myRect3', 'rect name not in names hash');
|
||||
|
||||
circle.setId('newCircleId');
|
||||
test(stage.ids['newCircleId'] !== undefined, 'circle not in ids hash');
|
||||
test(stage.ids['myCircle'] === undefined, 'old circle id key is still in ids hash');
|
||||
test(go.ids['newCircleId'] !== undefined, 'circle not in ids hash');
|
||||
test(go.ids['myCircle3'] === undefined, 'old circle id key is still in ids hash');
|
||||
|
||||
rect.setName('newRectName');
|
||||
test(stage.names['newRectName'][0] !== undefined, 'new rect name not in names hash');
|
||||
test(stage.names['myRect'] === undefined, 'old rect name is still in names hash');
|
||||
test(go.names['newRectName'][0] !== undefined, 'new rect name not in names hash');
|
||||
test(go.names['myRect3'] === undefined, 'old rect name is still in names hash');
|
||||
},
|
||||
'add layer': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
|
@@ -2252,20 +2252,14 @@ Test.Modules.NODE = {
|
||||
|
||||
var go = Kinetic.Global;
|
||||
|
||||
test(go.tempNodes[circle._id] === undefined, 'circle shouldn\'t be in the temp nodes hash');
|
||||
|
||||
layer.add(circle);
|
||||
|
||||
var node = stage.get('#myCircle')[0];
|
||||
|
||||
test(node === undefined, 'node should be undefined');
|
||||
|
||||
test(go.tempNodes[circle._id].attrs.id === 'myCircle', 'circle should be in temp nodes');
|
||||
|
||||
circle.destroy();
|
||||
|
||||
test(go.tempNodes[circle._id] === undefined, 'circle shouldn\'t be in the temp nodes hash');
|
||||
|
||||
},
|
||||
'destroy layer with shape': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
@@ -2288,7 +2282,7 @@ Test.Modules.NODE = {
|
||||
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
|
||||
|
||||
test(stage.children.length === 1, 'stage should have 1 children');
|
||||
test(stage.get('.myLayer')[0] !== undefined, 'layer should exist');
|
||||
test(stage.get('.myCircle')[0] !== undefined, 'circle should exist');
|
||||
@@ -2472,7 +2466,7 @@ Test.Modules.NODE = {
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
id: 'myCircle'
|
||||
id: 'myCircle2'
|
||||
});
|
||||
|
||||
var rect = new Kinetic.Rect({
|
||||
@@ -2483,32 +2477,33 @@ Test.Modules.NODE = {
|
||||
fill: 'purple',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
name: 'myRect'
|
||||
name: 'myRect2'
|
||||
});
|
||||
|
||||
var circleColorKey = circle.colorKey;
|
||||
var rectColorKey = rect.colorKey;
|
||||
var go = Kinetic.Global;
|
||||
|
||||
layer.add(circle);
|
||||
layer.add(rect);
|
||||
stage.add(layer);
|
||||
|
||||
test(stage.ids.myCircle._id === circle._id, 'circle not in ids hash');
|
||||
test(stage.names.myRect[0]._id === rect._id, 'rect not in names hash');
|
||||
test(go.ids.myCircle2._id === circle._id, 'circle not in ids hash');
|
||||
test(go.names.myRect2[0]._id === rect._id, 'rect not in names hash');
|
||||
test(Kinetic.Global.shapes[circleColorKey]._id === circle._id, 'circle color key should be in shapes hash');
|
||||
test(Kinetic.Global.shapes[rectColorKey]._id === rect._id, 'rect color key should be in shapes hash');
|
||||
|
||||
circle.destroy();
|
||||
|
||||
test(stage.ids.myCircle === undefined, 'circle still in hash');
|
||||
test(stage.names.myRect[0]._id === rect._id, 'rect not in names hash');
|
||||
test(go.ids.myCircle2 === undefined, 'circle still in hash');
|
||||
test(go.names.myRect2[0]._id === rect._id, 'rect not in names hash');
|
||||
test(Kinetic.Global.shapes[circleColorKey] === undefined, 'circle color key should not be in shapes hash');
|
||||
test(Kinetic.Global.shapes[rectColorKey]._id === rect._id, 'rect color key should be in shapes hash');
|
||||
|
||||
rect.destroy();
|
||||
|
||||
test(stage.ids.myCircle === undefined, 'circle still in hash');
|
||||
test(stage.names.myRect === undefined, 'rect still in hash');
|
||||
test(go.ids.myCircle2 === undefined, 'circle still in hash');
|
||||
test(go.names.myRect2 === undefined, 'rect still in hash');
|
||||
test(Kinetic.Global.shapes[circleColorKey] === undefined, 'circle color key should not be in shapes hash');
|
||||
test(Kinetic.Global.shapes[rectColorKey] === undefined, 'rect color key should not be in shapes hash');
|
||||
}
|
||||
|
Reference in New Issue
Block a user