1515var ReactComponentEnvironment = require ( 'ReactComponentEnvironment' ) ;
1616var ReactMultiChildUpdateTypes = require ( 'ReactMultiChildUpdateTypes' ) ;
1717
18- var flattenChildren = require ( 'flattenChildren' ) ;
19- var instantiateReactComponent = require ( 'instantiateReactComponent' ) ;
20- var shouldUpdateReactComponent = require ( 'shouldUpdateReactComponent' ) ;
18+ var ReactChildReconciler = require ( 'ReactChildReconciler' ) ;
2119
2220/**
2321 * Updating children of a component may trigger recursive updates. The depth is
@@ -179,25 +177,23 @@ var ReactMultiChild = {
179177 * @internal
180178 */
181179 mountChildren : function ( nestedChildren , transaction , context ) {
182- var children = flattenChildren ( nestedChildren ) ;
180+ var children = ReactChildReconciler . instantiateChildren (
181+ nestedChildren , transaction , context
182+ ) ;
183+ this . _renderedChildren = children ;
183184 var mountImages = [ ] ;
184185 var index = 0 ;
185- this . _renderedChildren = children ;
186186 for ( var name in children ) {
187187 var child = children [ name ] ;
188188 if ( children . hasOwnProperty ( name ) ) {
189- // The rendered children must be turned into instances as they're
190- // mounted.
191- var childInstance = instantiateReactComponent ( child , null ) ;
192- children [ name ] = childInstance ;
193189 // Inlined for performance, see `ReactInstanceHandles.createReactID`.
194190 var rootID = this . _rootNodeID + name ;
195- var mountImage = childInstance . mountComponent (
191+ var mountImage = child . mountComponent (
196192 rootID ,
197193 transaction ,
198194 context
199195 ) ;
200- childInstance . _mountIndex = index ;
196+ child . _mountIndex = index ;
201197 mountImages . push ( mountImage ) ;
202198 index ++ ;
203199 }
@@ -217,6 +213,8 @@ var ReactMultiChild = {
217213 try {
218214 var prevChildren = this . _renderedChildren ;
219215 // Remove any rendered children.
216+ ReactChildReconciler . unmountChildren ( prevChildren ) ;
217+ // TODO: The setTextContent operation should be enough
220218 for ( var name in prevChildren ) {
221219 if ( prevChildren . hasOwnProperty ( name ) ) {
222220 this . _unmountChildByName ( prevChildren [ name ] , name ) ;
@@ -264,8 +262,11 @@ var ReactMultiChild = {
264262 * @protected
265263 */
266264 _updateChildren : function ( nextNestedChildren , transaction , context ) {
267- var nextChildren = flattenChildren ( nextNestedChildren ) ;
268265 var prevChildren = this . _renderedChildren ;
266+ var nextChildren = ReactChildReconciler . updateChildren (
267+ prevChildren , nextNestedChildren , transaction , context
268+ ) ;
269+ this . _renderedChildren = nextChildren ;
269270 if ( ! nextChildren && ! prevChildren ) {
270271 return ;
271272 }
@@ -279,12 +280,10 @@ var ReactMultiChild = {
279280 continue ;
280281 }
281282 var prevChild = prevChildren && prevChildren [ name ] ;
282- var prevElement = prevChild && prevChild . _currentElement ;
283- var nextElement = nextChildren [ name ] ;
284- if ( shouldUpdateReactComponent ( prevElement , nextElement ) ) {
283+ var nextChild = nextChildren [ name ] ;
284+ if ( prevChild === nextChild ) {
285285 this . moveChild ( prevChild , nextIndex , lastIndex ) ;
286286 lastIndex = Math . max ( prevChild . _mountIndex , lastIndex ) ;
287- prevChild . receiveComponent ( nextElement , transaction , context ) ;
288287 prevChild . _mountIndex = nextIndex ;
289288 } else {
290289 if ( prevChild ) {
@@ -293,12 +292,8 @@ var ReactMultiChild = {
293292 this . _unmountChildByName ( prevChild , name ) ;
294293 }
295294 // The child must be instantiated before it's mounted.
296- var nextChildInstance = instantiateReactComponent (
297- nextElement ,
298- null
299- ) ;
300295 this . _mountChildByNameAtIndex (
301- nextChildInstance , name , nextIndex , transaction , context
296+ nextChild , name , nextIndex , transaction , context
302297 ) ;
303298 }
304299 nextIndex ++ ;
@@ -320,13 +315,7 @@ var ReactMultiChild = {
320315 */
321316 unmountChildren : function ( ) {
322317 var renderedChildren = this . _renderedChildren ;
323- for ( var name in renderedChildren ) {
324- var renderedChild = renderedChildren [ name ] ;
325- // TODO: When is this not true?
326- if ( renderedChild . unmountComponent ) {
327- renderedChild . unmountComponent ( ) ;
328- }
329- }
318+ ReactChildReconciler . unmountChildren ( renderedChildren ) ;
330319 this . _renderedChildren = null ;
331320 } ,
332321
@@ -404,8 +393,6 @@ var ReactMultiChild = {
404393 ) ;
405394 child . _mountIndex = index ;
406395 this . createChild ( child , mountImage ) ;
407- this . _renderedChildren = this . _renderedChildren || { } ;
408- this . _renderedChildren [ name ] = child ;
409396 } ,
410397
411398 /**
@@ -420,8 +407,6 @@ var ReactMultiChild = {
420407 _unmountChildByName : function ( child , name ) {
421408 this . removeChild ( child ) ;
422409 child . _mountIndex = null ;
423- child . unmountComponent ( ) ;
424- delete this . _renderedChildren [ name ] ;
425410 }
426411
427412 }
0 commit comments