@@ -113,7 +113,16 @@ function ImportedElement({ model }) {
113113 const attributes = elementAttributes ( model , config . sendEvent ) ;
114114 return html `< ${ cmpt } ...${ attributes } > ${ children } </ /> ` ;
115115 } 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+ }
117126 }
118127}
119128
@@ -128,18 +137,6 @@ function StandardElement({ model }) {
128137 }
129138}
130139
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-
143140function elementChildren ( model ) {
144141 if ( ! model . children ) {
145142 return [ ] ;
@@ -197,41 +194,11 @@ function eventHandler(sendEvent, eventSpec) {
197194function useLazyModule ( source , sourceUrlBase = "" ) {
198195 const [ module , setModule ] = react . useState ( null ) ;
199196 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 ) ;
207198 }
208199 return module ;
209200}
210201
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-
235202function getPathProperty ( obj , prop ) {
236203 // properties may be dot seperated strings
237204 const path = prop . split ( "." ) ;
@@ -281,3 +248,9 @@ function useForceUpdate() {
281248 const [ , updateState ] = react . useState ( ) ;
282249 return react . useCallback ( ( ) => updateState ( { } ) , [ ] ) ;
283250}
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