@@ -113,7 +113,16 @@ function ImportedElement({ model }) {
113
113
const attributes = elementAttributes ( model , config . sendEvent ) ;
114
114
return html `< ${ cmpt } ...${ attributes } > ${ children } </ /> ` ;
115
115
} else {
116
- return createElement ( model . importSource . fallback ) ;
116
+ const fallback = model . importSource . fallback ;
117
+ if ( ! fallback ) {
118
+ return html `< div /> ` ;
119
+ }
120
+ switch ( typeof fallback ) {
121
+ case "object" :
122
+ return html `< ${ Element } model =${ fallback } /> ` ;
123
+ case "string" :
124
+ return html `< div > ${ fallback } </ div > ` ;
125
+ }
117
126
}
118
127
}
119
128
@@ -128,18 +137,6 @@ function StandardElement({ model }) {
128
137
}
129
138
}
130
139
131
- function createElement ( value ) {
132
- if ( ! value ) {
133
- return html `< div /> ` ;
134
- }
135
- switch ( typeof value ) {
136
- case "object" :
137
- return html `< ${ Element } model =${ value } /> ` ;
138
- case "string" :
139
- return html `< div > ${ value } </ div > ` ;
140
- }
141
- }
142
-
143
140
function elementChildren ( model ) {
144
141
if ( ! model . children ) {
145
142
return [ ] ;
@@ -197,41 +194,11 @@ function eventHandler(sendEvent, eventSpec) {
197
194
function useLazyModule ( source , sourceUrlBase = "" ) {
198
195
const [ module , setModule ] = react . useState ( null ) ;
199
196
if ( ! module ) {
200
- dynamicImport (
201
- source . startsWith ( "./" )
202
- ? ( sourceUrlBase . endsWith ( "/" )
203
- ? sourceUrlBase . slice ( 0 , - 1 )
204
- : sourceUrlBase ) + source . slice ( 1 )
205
- : source
206
- ) . then ( setModule ) ;
197
+ import ( joinUrl ( sourceUrlBase , source ) ) . then ( setModule ) ;
207
198
}
208
199
return module ;
209
200
}
210
201
211
- function dynamicImport ( source ) {
212
- return import ( source ) . then (
213
- ( pkg ) => ( pkg . default ? pkg . default : pkg ) ,
214
- ( error ) => {
215
- if ( ! error . stack ) {
216
- throw error ;
217
- } else {
218
- console . log ( error ) ;
219
- return {
220
- default ( ) {
221
- return html `
222
- < pre >
223
- < h1 > Error</ h1 >
224
- < code > ${ [ error . stack , error . message ] } </ code >
225
- </ pre
226
- >
227
- ` ;
228
- } ,
229
- } ;
230
- }
231
- }
232
- ) ;
233
- }
234
-
235
202
function getPathProperty ( obj , prop ) {
236
203
// properties may be dot seperated strings
237
204
const path = prop . split ( "." ) ;
@@ -281,3 +248,9 @@ function useForceUpdate() {
281
248
const [ , updateState ] = react . useState ( ) ;
282
249
return react . useCallback ( ( ) => updateState ( { } ) , [ ] ) ;
283
250
}
251
+
252
+ function joinUrl ( base , tail ) {
253
+ return tail . startsWith ( "./" )
254
+ ? ( base . endsWith ( "/" ) ? base . slice ( 0 , - 1 ) : base ) + tail . slice ( 1 )
255
+ : tail ;
256
+ }
0 commit comments