7
7
contains ,
8
8
filter ,
9
9
forEach ,
10
+ has ,
10
11
isEmpty ,
11
12
isNil ,
12
13
keysIn ,
@@ -25,6 +26,29 @@ import { assertPropTypes } from 'check-prop-types';
25
26
const SIMPLE_COMPONENT_TYPES = [ 'String' , 'Number' , 'Null' , 'Boolean' ] ;
26
27
const isSimpleComponent = component => contains ( type ( component ) , SIMPLE_COMPONENT_TYPES )
27
28
29
+ function validateComponent ( componentDefinition ) {
30
+ if ( type ( componentDefinition ) === 'Array' ) {
31
+ throw new Error (
32
+ 'The children property of a component is a list of lists, instead ' +
33
+ 'of just a list. ' +
34
+ 'Check the component that has the following contents, ' +
35
+ 'and remove of the levels of nesting: \n' +
36
+ JSON . stringify ( componentDefinition , null , 2 )
37
+ ) ;
38
+ }
39
+ if ( type ( componentDefinition ) === 'Object' &&
40
+ ! ( has ( 'namespace' , componentDefinition ) &&
41
+ has ( 'type' , componentDefinition ) &&
42
+ has ( 'props' , componentDefinition ) ) ) {
43
+ throw new Error (
44
+ 'An object was provided as `children` instead of a component, ' +
45
+ 'string, or number (or list of those). ' +
46
+ 'Check the children property that looks something like:\n' +
47
+ JSON . stringify ( componentDefinition , null , 2 )
48
+ ) ;
49
+ }
50
+ }
51
+
28
52
const createContainer = component => isSimpleComponent ( component ) ?
29
53
component :
30
54
( < AugmentedTreeContainer
@@ -72,21 +96,9 @@ class TreeContainer extends Component {
72
96
if ( isSimpleComponent ( _dashprivate_layout ) ) {
73
97
return _dashprivate_layout ;
74
98
}
99
+ validateComponent ( _dashprivate_layout ) ;
75
100
76
- if ( ! _dashprivate_layout . type ) {
77
- /* eslint-disable no-console */
78
- console . error ( type ( _dashprivate_layout ) , _dashprivate_layout ) ;
79
- /* eslint-enable no-console */
80
- throw new Error ( 'component.type is undefined' ) ;
81
- }
82
- if ( ! _dashprivate_layout . namespace ) {
83
- /* eslint-disable no-console */
84
- console . error ( type ( _dashprivate_layout ) , _dashprivate_layout ) ;
85
- /* eslint-enable no-console */
86
- throw new Error ( 'component.namespace is undefined' ) ;
87
- }
88
-
89
- const element = Registry . resolve ( _dashprivate_layout . type , _dashprivate_layout . namespace ) ;
101
+ const element = Registry . resolve ( _dashprivate_layout ) ;
90
102
91
103
const layout = omit ( [ 'children' ] , _dashprivate_layout . props ) ;
92
104
@@ -178,7 +190,8 @@ TreeContainer.propTypes = {
178
190
} ;
179
191
180
192
function isLoadingComponent ( layout ) {
181
- return Registry . resolve ( layout . type , layout . namespace ) . _dashprivate_isLoadingComponent ;
193
+ validateComponent ( layout ) ;
194
+ return Registry . resolve ( layout ) . _dashprivate_isLoadingComponent ;
182
195
}
183
196
184
197
function getNestedIds ( layout ) {
0 commit comments