@@ -4,41 +4,15 @@ import { bindActionCreators } from 'redux';
44import { createStructuredSelector } from 'reselect' ;
55import createContainerSelector from '../../store/selectors' ;
66import createContainerActions from '../../store/actions' ;
7- import { getComponentName } from '../NotFoundComponent/NotFoundComponent' ;
87
98let sendDebugMessage ;
109let constants ;
1110if ( process . env . NODE_ENV !== 'production' ) {
1211 sendDebugMessage = require ( '../../commons/sendMessage' ) . default ;
1312 constants = require ( '../../commons/constants' ) ;
1413}
15- class ErrorBoundary extends React . Component {
16- constructor ( props ) {
17- super ( props ) ;
18- this . state = { hasError : false , error : null } ;
19- }
20-
21- componentDidCatch ( error , info ) {
22- this . setState ( { hasError : true , error } ) ;
23- }
24-
25- render ( ) {
26- const { hasError, error} = this . state ;
27- if ( hasError ) {
28- const { componentName } = this . props ;
29- return (
30- < div style = { { color : 'white' , backgroundColor : 'red' , borderRadius : '4px' , padding : '.5em' } } >
31- < code > Error occurred in "{ getComponentName ( componentName ) } " component: </ code >
32- < code > { error && error . message } </ code >
33- </ div >
34- ) ;
35- }
36- return this . props . children ;
37- }
38- }
3914
4015class Container extends React . Component {
41-
4216 constructor ( props , context ) {
4317 super ( props , context ) ;
4418 const {
@@ -98,11 +72,29 @@ class Container extends React.Component {
9872 wrappedComponent,
9973 wrappedProps,
10074 stateProps,
75+ populatedProps,
76+ cloneProps, // this props may come from the parent component that wants to clone this instance
77+ children
78+ } = this . props ;
79+ return React . createElement (
80+ wrappedComponent ,
81+ { ...wrappedProps , ...cloneProps , ...this . wrappedHandlers , ...populatedProps , ...stateProps } ,
82+ children
83+ ) ;
84+ }
85+ }
86+
87+ class Component extends React . Component {
88+ render ( ) {
89+ const {
90+ wrappedComponent,
91+ wrappedProps,
92+ cloneProps, // this props may come from the parent component that wants to clone this instance
10193 children
10294 } = this . props ;
10395 return React . createElement (
10496 wrappedComponent ,
105- { ...wrappedProps , ...this . wrappedHandlers , ... stateProps } ,
97+ { ...wrappedProps , ...cloneProps } ,
10698 children
10799 ) ;
108100 }
@@ -116,6 +108,7 @@ export default function createContainer (
116108 containerEventHandlers ,
117109 containerProperties ,
118110 props = { } ,
111+ populatedProps ,
119112 nestedComponents = null
120113) {
121114
@@ -147,26 +140,20 @@ export default function createContainer (
147140 containerEventHandlers,
148141 containerProperties,
149142 wrappedProps : props ,
143+ populatedProps,
150144 wrappedComponent,
151145 } ;
152146
153- return (
154- < ErrorBoundary key = { `errorBoundary_${ props . key } ` } componentName = { componentName } >
155- { React . createElement (
156- connect ( mapStateToProps , mapDispatchToProps ) ( Container ) ,
157- wrapperProps ,
158- nestedComponents
159- ) }
160- </ ErrorBoundary >
147+ return React . createElement (
148+ connect ( mapStateToProps , mapDispatchToProps ) ( Container ) ,
149+ { ...wrapperProps , key : `container_${ props . key } ` } ,
150+ nestedComponents
161151 ) ;
162152 }
163- return (
164- < ErrorBoundary key = { `errorBoundary_${ props . key } ` } componentName = { componentName } >
165- { React . createElement (
166- wrappedComponent ,
167- props ,
168- nestedComponents
169- ) }
170- </ ErrorBoundary >
153+
154+ return React . createElement (
155+ Component ,
156+ { wrappedComponent, wrappedProps : props , key : `component_${ props . key } ` } ,
157+ nestedComponents
171158 ) ;
172159}
0 commit comments