@@ -9,7 +9,7 @@ import util, { hashShort } from './util.ts'
9
9
export function ALEPH ( { initial } : {
10
10
initial : {
11
11
manifest : AppManifest
12
- pageModules : Record < string , { moduleId : string , hash : string } >
12
+ pageModules : Record < string , Module >
13
13
url : RouterURL
14
14
data : Record < string , any >
15
15
components : Record < string , ComponentType < any > >
@@ -80,16 +80,16 @@ export function ALEPH({ initial }: {
80
80
console . log ( '[DATA]' , data )
81
81
setData ( data )
82
82
}
83
- const onAddModule = async ( { moduleId , hash } : Module ) => {
84
- if ( moduleId === '/404.js' ) {
85
- const { default : Component } = await import ( getModuleImportUrl ( baseUrl , { moduleId , hash } ) + '?t=' + Date . now ( ) )
83
+ const onAddModule = async ( mod : Module ) => {
84
+ if ( mod . id === '/404.js' ) {
85
+ const { default : Component } = await import ( getModuleImportUrl ( baseUrl , mod ) + '?t=' + Date . now ( ) )
86
86
if ( util . isLikelyReactComponent ( Component ) ) {
87
87
setE404 ( { Component } )
88
88
} else {
89
89
setE404 ( { Component : E404Page } )
90
90
}
91
- } else if ( moduleId === '/app.js' ) {
92
- const { default : Component } = await import ( getModuleImportUrl ( baseUrl , { moduleId , hash } ) + '?t=' + Date . now ( ) )
91
+ } else if ( mod . id === '/app.js' ) {
92
+ const { default : Component } = await import ( getModuleImportUrl ( baseUrl , mod ) + '?t=' + Date . now ( ) )
93
93
if ( util . isLikelyReactComponent ( Component ) ) {
94
94
setApp ( { Component } )
95
95
} else {
@@ -98,15 +98,15 @@ export function ALEPH({ initial }: {
98
98
Component : E501App
99
99
} ) )
100
100
}
101
- } else if ( moduleId === '/data.js' || moduleId === '/data/index.js' ) {
102
- const { default : data } = await import ( getModuleImportUrl ( baseUrl , { moduleId , hash } ) + '?t=' + Date . now ( ) )
101
+ } else if ( mod . id === '/data.js' || mod . id === '/data/index.js' ) {
102
+ const { default : data } = await import ( getModuleImportUrl ( baseUrl , mod ) + '?t=' + Date . now ( ) )
103
103
console . log ( '[DATA]' , data )
104
104
setData ( data )
105
- } else if ( moduleId . startsWith ( '/pages/' ) ) {
106
- const pagePath = util . trimSuffix ( moduleId , '.js' ) . replace ( / \s + / g, '-' ) . replace ( / \/ ? i n d e x $ / i, '/' )
105
+ } else if ( mod . id . startsWith ( '/pages/' ) ) {
106
+ const pagePath = util . trimSuffix ( mod . id , '.js' ) . replace ( / \s + / g, '-' ) . replace ( / \/ ? i n d e x $ / i, '/' )
107
107
setPageModules ( pageModules => ( {
108
108
...pageModules ,
109
- [ pagePath ] : { moduleId , hash }
109
+ [ pagePath ] : mod
110
110
} ) )
111
111
}
112
112
}
@@ -120,10 +120,10 @@ export function ALEPH({ initial }: {
120
120
setData ( { } )
121
121
} else if ( moduleId . startsWith ( '/pages/' ) ) {
122
122
setPageModules ( pageModules => {
123
- const newPageModules : Record < string , { moduleId : string , hash : string } > = { }
123
+ const newPageModules : Record < string , Module > = { }
124
124
for ( const pagePath in pageModules ) {
125
125
const mod = pageModules [ pagePath ]
126
- if ( mod . moduleId !== moduleId ) {
126
+ if ( mod . id !== moduleId ) {
127
127
newPageModules [ pagePath ] = mod
128
128
}
129
129
}
@@ -192,6 +192,6 @@ export async function redirect(url: string, replace: boolean) {
192
192
events . emit ( 'popstate' , { type : 'popstate' } )
193
193
}
194
194
195
- export function getModuleImportUrl ( baseUrl : string , { moduleId , hash } : Module ) {
196
- return util . cleanPath ( baseUrl + '/_aleph/' + moduleId . replace ( / \. j s $ / , `.${ hash . slice ( 0 , hashShort ) } .js` ) )
195
+ export function getModuleImportUrl ( baseUrl : string , mod : Module ) {
196
+ return util . cleanPath ( baseUrl + '/_aleph/' + mod . id . replace ( / \. j s $ / , `.${ mod . hash . slice ( 0 , hashShort ) } .js` ) )
197
197
}
0 commit comments