Assign the same keys if it's a single nested array or not

If you specify a single array, we didn't prefix the keys with 0.

If you later add children, the first array won't have the same key.
This commit is contained in:
CommitSyncScript
2013-06-07 22:10:20 -07:00
committed by Paul O’Shannessy
parent 582359aeea
commit 7e7579e1ba
3 changed files with 17 additions and 12 deletions
+1 -1
View File
@@ -87,7 +87,7 @@ function tryToReuseArray(children) {
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (isEmptyChild(child)) return false;
assignKey('', child, i);
assignKey('0', child, i);
}
return true;
}
+11 -8
View File
@@ -67,8 +67,8 @@ describe('ReactIdentity', function() {
React.renderComponent(instance, document.createElement('div'));
var node = instance.getDOMNode();
reactComponentExpect(instance).toBeDOMComponentWithChildCount(2);
checkId(node.childNodes[0], '.reactRoot[0].[apple]');
checkId(node.childNodes[1], '.reactRoot[0].[banana]');
checkId(node.childNodes[0], '.reactRoot[0].[0:apple]');
checkId(node.childNodes[1], '.reactRoot[0].[0:banana]');
});
it('should use instance identity', function() {
@@ -89,12 +89,15 @@ describe('ReactIdentity', function() {
React.renderComponent(instance, document.createElement('div'));
var node = instance.getDOMNode();
reactComponentExpect(instance).toBeDOMComponentWithChildCount(3);
checkId(node.childNodes[0], '.reactRoot[0].[wrap1]');
checkId(node.childNodes[0].firstChild, '.reactRoot[0].[wrap1].[squirrel]');
checkId(node.childNodes[1], '.reactRoot[0].[wrap2]');
checkId(node.childNodes[1].firstChild, '.reactRoot[0].[wrap2].[bunny]');
checkId(node.childNodes[2], '.reactRoot[0].[2]');
checkId(node.childNodes[2].firstChild, '.reactRoot[0].[2].[chipmunk]');
checkId(node.childNodes[0], '.reactRoot[0].[0:wrap1]');
checkId(
node.childNodes[0].firstChild,
'.reactRoot[0].[0:wrap1].[0:squirrel]'
);
checkId(node.childNodes[1], '.reactRoot[0].[0:wrap2]');
checkId(node.childNodes[1].firstChild, '.reactRoot[0].[0:wrap2].[0:bunny]');
checkId(node.childNodes[2], '.reactRoot[0].[0:2]');
checkId(node.childNodes[2].firstChild, '.reactRoot[0].[0:2].[0:chipmunk]');
});
it('should let restructured components retain their uniqueness', function() {
+5 -3
View File
@@ -75,7 +75,7 @@ describe('mapChildren', function() {
expect(mapFn).toHaveBeenCalledWith(simpleKid, 'simple', 0);
expect(rendered.props.children[0]).toBe(simpleKid);
expect(rendered.props.children).toHaveKeys(['simple']);
expect(rendered.props.children).toHaveKeys(['0:simple']);
});
it('should pass key to returned component', function() {
@@ -94,7 +94,7 @@ describe('mapChildren', function() {
expect(rendered.props.children[0]).not.toBe(simpleKid);
expect(rendered.props.children[0].props.children[0]).toBe(simpleKid);
expect(rendered.props.children).toHaveKeys(['simple']);
expect(rendered.props.children).toHaveKeys(['0:simple']);
expect(rendered.props.children[0].props.children).toHaveKeys(['simple']);
});
@@ -126,6 +126,8 @@ describe('mapChildren', function() {
expect(mapFn).toHaveBeenCalledWith(kidTwo, '0:two', 1);
expect(mapFn).toHaveBeenCalledWith(kidThree, '0:three', 2);
expect(rendered.props.children).not.toEqual(instance.props.children);
expect(rendered.props.children).toHaveKeys(['0:one', '0:two', '0:three']);
expect(rendered.props.children).toHaveKeys([
'0:0:one', '0:0:two', '0:0:three'
]);
});
});