@@ -29,7 +29,7 @@ export const setHasBabelPlugin = () => {
29
29
}
30
30
31
31
export default function universal < Props : Props > (
32
- component : Config | ConfigFunc,
32
+ asyncModule : Config | ConfigFunc,
33
33
opts: ComponentOptions = { }
34
34
) {
35
35
const {
@@ -52,7 +52,6 @@ export default function universal<Props: Props>(
52
52
/* eslint-disable react/sort-comp */
53
53
_mounted : boolean
54
54
_asyncOnly : boolean
55
- _component : ?Object
56
55
57
56
state : State
58
57
props : Props
@@ -61,43 +60,43 @@ export default function universal<Props: Props>(
61
60
62
61
static preload ( props : Props , context : Object = { } ) {
63
62
props = props || { }
64
- const { requireAsync , requireSync } = req ( component , options , props )
65
- let Component
63
+ const { requireAsync , requireSync } = req ( asyncModule , options , props )
64
+ let mod
66
65
67
66
try {
68
- Component = requireSync ( props , context )
67
+ mod = requireSync ( props , context )
69
68
}
70
69
catch ( error ) {
71
70
return Promise . reject ( error )
72
71
}
73
72
74
73
return Promise . resolve ( )
75
74
. then ( ( ) => {
76
- if ( Component ) return Component
75
+ if ( mod ) return mod
77
76
return requireAsync ( props , context )
78
77
} )
79
- . then ( Component => {
80
- hoist ( UniversalComponent , Component , {
78
+ . then ( mod => {
79
+ hoist ( UniversalComponent , mod , {
81
80
preload : true ,
82
81
preloadWeak : true
83
82
} )
84
- return Component
83
+ return mod
85
84
} )
86
85
}
87
86
88
87
static preloadWeak ( props : Props , context : Object = { } ) {
89
88
props = props || { }
90
- const { requireSync } = req ( component , options , props )
89
+ const { requireSync } = req ( asyncModule , options , props )
91
90
92
- const Component = requireSync ( props , context )
93
- if ( Component ) {
94
- hoist ( UniversalComponent , Component , {
91
+ const mod = requireSync ( props , context )
92
+ if ( mod ) {
93
+ hoist ( UniversalComponent , mod , {
95
94
preload : true ,
96
95
preloadWeak : true
97
96
} )
98
97
}
99
98
100
- return Component
99
+ return mod
101
100
}
102
101
103
102
static contextTypes = {
@@ -114,15 +113,15 @@ export default function universal<Props: Props>(
114
113
this . _mounted = true
115
114
116
115
const { addModule , requireSync , requireAsync , asyncOnly } = req (
117
- component ,
116
+ asyncModule ,
118
117
options ,
119
118
this . props
120
119
)
121
120
122
- let Component
121
+ let mod
123
122
124
123
try {
125
- Component = requireSync ( this . props , this . context )
124
+ mod = requireSync ( this . props , this . context )
126
125
}
127
126
catch ( error ) {
128
127
return this . update ( { error } )
@@ -135,9 +134,9 @@ export default function universal<Props: Props>(
135
134
this . context . report ( chunkName )
136
135
}
137
136
138
- if ( Component || isServer ) {
137
+ if ( mod || isServer ) {
139
138
this . handleBefore ( true , true , isServer )
140
- this . update ( { Component } , true , true , isServer )
139
+ this . update ( { mod } , true , true , isServer )
141
140
return
142
141
}
143
142
@@ -152,56 +151,56 @@ export default function universal<Props: Props>(
152
151
componentWillReceiveProps ( nextProps : Props ) {
153
152
if ( isDynamic || this . _asyncOnly ) {
154
153
const { requireSync, requireAsync, shouldUpdate } = req (
155
- component ,
154
+ asyncModule ,
156
155
options ,
157
156
nextProps ,
158
157
this . props
159
158
)
160
159
161
160
if ( shouldUpdate ( nextProps , this . props ) ) {
162
- let Component
161
+ let mod
163
162
164
163
try {
165
- Component = requireSync ( nextProps , this . context )
164
+ mod = requireSync ( nextProps , this . context )
166
165
}
167
166
catch ( error ) {
168
167
return this . update ( { error } )
169
168
}
170
169
171
- this . handleBefore ( false , ! ! Component )
170
+ this . handleBefore ( false , ! ! mod )
172
171
173
- if ( ! Component ) {
172
+ if ( ! mod ) {
174
173
return this . requireAsync ( requireAsync , nextProps )
175
174
}
176
175
177
- const state = { Component }
176
+ const state = { mod }
178
177
179
178
if ( alwaysDelay ) {
180
- if ( loadingTransition ) this . update ( { Component : null } ) // display `loading` during componentWillReceiveProps
179
+ if ( loadingTransition ) this . update ( { mod : null } ) // display `loading` during componentWillReceiveProps
181
180
setTimeout ( ( ) => this . update ( state , false , true ) , minDelay )
182
181
return
183
182
}
184
183
185
184
this . update ( state , false , true )
186
185
}
187
186
else if ( isHMR ( ) ) {
188
- const Component = requireSync ( nextProps , this . context )
189
- this . setState ( { Component : ( ) => null } ) // HMR /w Redux and HOCs can be finicky, so we
190
- setTimeout ( ( ) => this . setState ( { Component } ) ) // toggle components to insure updates occur
187
+ const mod = requireSync ( nextProps , this . context )
188
+ this . setState ( { mod : ( ) => null } ) // HMR /w Redux and HOCs can be finicky, so we
189
+ setTimeout ( ( ) => this . setState ( { mod } ) ) // toggle components to insure updates occur
191
190
}
192
191
}
193
192
}
194
193
195
194
requireAsync ( requireAsync : RequireAsync , props : Props , isMount ? : boolean ) {
196
- if ( this . state . Component && loadingTransition ) {
197
- this . update ( { Component : null } ) // display `loading` during componentWillReceiveProps
195
+ if ( this . state . mod && loadingTransition ) {
196
+ this . update ( { mod : null } ) // display `loading` during componentWillReceiveProps
198
197
}
199
198
200
199
const time = new Date ( )
201
200
202
201
requireAsync ( props , this . context )
203
- . then ( ( Component : ?any ) => {
204
- const state = { Component }
202
+ . then ( ( mod : ?any ) => {
203
+ const state = { mod }
205
204
206
205
const timeLapsed = new Date ( ) - time
207
206
if ( timeLapsed < minDelay ) {
@@ -244,18 +243,18 @@ export default function universal<Props: Props>(
244
243
isSync : boolean ,
245
244
isServer : boolean
246
245
) {
247
- const { Component , error } = state
246
+ const { mod , error } = state
248
247
249
- if ( Component && ! error ) {
250
- hoist ( UniversalComponent , Component , {
248
+ if ( mod && ! error ) {
249
+ hoist ( UniversalComponent , mod , {
251
250
preload : true ,
252
251
preloadWeak : true
253
252
} )
254
253
255
254
if ( this . props . onAfter ) {
256
255
const { onAfter } = this . props
257
256
const info = { isMount, isSync, isServer }
258
- onAfter ( info , Component )
257
+ onAfter ( info , mod )
259
258
}
260
259
}
261
260
else if ( error && this . props . onError ) {
@@ -266,7 +265,7 @@ export default function universal<Props: Props>(
266
265
}
267
266
268
267
render ( ) {
269
- const { error , Component } = this . state
268
+ const { error , mod } = this . state
270
269
const { isLoading , error : userError , ...props } = this . props
271
270
272
271
// user-provided props (e.g. for data-fetching loading):
@@ -279,9 +278,9 @@ export default function universal<Props: Props>(
279
278
else if ( error ) {
280
279
return createElement ( Err , { ...props , error } )
281
280
}
282
- else if ( Component ) {
281
+ else if ( mod ) {
283
282
// primary usage (for async import loading + errors):
284
- return createElement ( Component , props )
283
+ return createElement ( mod , props )
285
284
}
286
285
287
286
return createElement ( Loading , props )
0 commit comments