@@ -28,30 +28,30 @@ class GlobalTarget extends Component {
2828
2929 this . stackTypes = [ ]
3030
31- this . SetContextComponent = createSetContextComponent ( { } )
32-
3331 this . state = {
3432 stack : [ ] ,
3533 }
3634 }
3735
3836 componentDidMount ( ) {
3937 this . renderInRemote = ( { jsx, context, contextTypes } ) => {
40- this . SetContextComponent = createSetContextComponent ( contextTypes )
38+ const newStackItem = {
39+ jsx,
40+ SetContextComponent : createSetContextComponent ( contextTypes ) ,
41+ context
42+ } ;
4143
4244 if ( this . stackTypes . filter ( type => type === jsx . type ) . length === 0 ) {
4345 this . stackTypes = [ ...this . stackTypes , jsx . type ]
4446
4547 this . setState ( ( { stack } ) => ( {
46- context,
47- stack : [ ...stack , jsx ] ,
48+ stack : [ ...stack , newStackItem ] ,
4849 } ) )
4950
5051 this . props . onAddStackElement ( jsx )
5152 } else {
5253 this . setState ( ( { stack } ) => ( {
53- context,
54- stack : stack . map ( item => ( item . type === jsx . type ? jsx : item ) ) ,
54+ stack : stack . map ( item => ( item . jsx . type === jsx . type ? newStackItem : item ) ) ,
5555 } ) )
5656 }
5757 }
@@ -61,7 +61,7 @@ class GlobalTarget extends Component {
6161
6262 this . setState (
6363 ( { stack } ) => ( {
64- stack : stack . filter ( ( { type } ) => type !== jsx . type ) ,
64+ stack : stack . filter ( item => item . jsx . type !== jsx . type ) ,
6565 } ) ,
6666 ( ) => {
6767 this . props . onRemoveStackElement ( jsx )
@@ -77,21 +77,20 @@ class GlobalTarget extends Component {
7777 }
7878
7979 render ( ) {
80- const { context , stack } = this . state
80+ const { stack } = this . state
8181
8282 return (
83- < this . SetContextComponent context = { context } >
84- { stack . map ( ( jsx , index ) => {
83+ < React . Fragment >
84+ { stack . map ( ( { jsx, SetContextComponent , context } , index ) => {
8585 return (
86- < div
87- key = { index }
88- style = { { display : index === stack . length - 1 ? 'block' : 'none' } }
89- >
90- { jsx }
91- </ div >
86+ < SetContextComponent key = { index } context = { context } >
87+ < div style = { { display : index === stack . length - 1 ? 'block' : 'none' } } >
88+ { jsx }
89+ </ div >
90+ </ SetContextComponent >
9291 )
9392 } ) }
94- </ this . SetContextComponent >
93+ </ React . Fragment >
9594 )
9695 }
9796}
0 commit comments