@@ -17,14 +17,32 @@ var ReactReconciler = require('ReactReconciler');
17
17
var flattenChildren = require ( 'flattenChildren' ) ;
18
18
var instantiateReactComponent = require ( 'instantiateReactComponent' ) ;
19
19
var shouldUpdateReactComponent = require ( 'shouldUpdateReactComponent' ) ;
20
+ var traverseAllChildren = require ( 'traverseAllChildren' ) ;
21
+ var warning = require ( 'warning' ) ;
22
+
23
+ function instantiateChild ( childInstances , child , name ) {
24
+ // We found a component instance.
25
+ var keyUnique = ( childInstances [ name ] === undefined ) ;
26
+ if ( __DEV__ ) {
27
+ warning (
28
+ keyUnique ,
29
+ 'flattenChildren(...): Encountered two children with the same key, ' +
30
+ '`%s`. Child keys must be unique; when two children share a key, only ' +
31
+ 'the first child will be used.' ,
32
+ name
33
+ ) ;
34
+ }
35
+ if ( child != null && keyUnique ) {
36
+ childInstances [ name ] = instantiateReactComponent ( child , null ) ;
37
+ }
38
+ }
20
39
21
40
/**
22
41
* ReactChildReconciler provides helpers for initializing or updating a set of
23
42
* children. Its output is suitable for passing it onto ReactMultiChild which
24
43
* does diffed reordering and insertion.
25
44
*/
26
45
var ReactChildReconciler = {
27
-
28
46
/**
29
47
* Generates a "mount image" for each of the supplied children. In the case
30
48
* of `ReactDOMComponent`, a mount image is a string of markup.
@@ -34,17 +52,12 @@ var ReactChildReconciler = {
34
52
* @internal
35
53
*/
36
54
instantiateChildren : function ( nestedChildNodes , transaction , context ) {
37
- var children = flattenChildren ( nestedChildNodes ) ;
38
- for ( var name in children ) {
39
- if ( children . hasOwnProperty ( name ) ) {
40
- var child = children [ name ] ;
41
- // The rendered children must be turned into instances as they're
42
- // mounted.
43
- var childInstance = instantiateReactComponent ( child , null ) ;
44
- children [ name ] = childInstance ;
45
- }
55
+ if ( nestedChildNodes == null ) {
56
+ return null ;
46
57
}
47
- return children ;
58
+ var childInstances = { } ;
59
+ traverseAllChildren ( nestedChildNodes , instantiateChild , childInstances ) ;
60
+ return childInstances ;
48
61
} ,
49
62
50
63
/**
0 commit comments