mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 23:56:51 +00:00
Only start getting schemas once on page load
This commit is contained in:
@@ -25,7 +25,7 @@ type VersionData = {
|
||||
schemas: SchemaRegistry,
|
||||
blockStates: BlockStateRegistry,
|
||||
}
|
||||
const Versions: Record<string, VersionData> = {}
|
||||
const Versions: Record<string, VersionData | Promise<VersionData>> = {}
|
||||
|
||||
type ModelData = {
|
||||
model: DataModel,
|
||||
@@ -46,15 +46,19 @@ const versionGetter: {
|
||||
|
||||
async function getVersion(id: VersionId): Promise<VersionData> {
|
||||
if (!Versions[id]) {
|
||||
try {
|
||||
const collections = versionGetter[id].getCollections()
|
||||
const blockStates: BlockStateRegistry = {}
|
||||
await fetchData(id, collections, blockStates)
|
||||
const schemas = versionGetter[id].getSchemas(collections)
|
||||
Versions[id] = { collections, schemas, blockStates }
|
||||
} catch (e) {
|
||||
throw new Error(`Cannot get version "${id}": ${e.message}`)
|
||||
}
|
||||
Versions[id] = (async () => {
|
||||
try {
|
||||
const collections = versionGetter[id].getCollections()
|
||||
const blockStates: BlockStateRegistry = {}
|
||||
await fetchData(id, collections, blockStates)
|
||||
const schemas = versionGetter[id].getSchemas(collections)
|
||||
Versions[id] = { collections, schemas, blockStates }
|
||||
return Versions[id]
|
||||
} catch (e) {
|
||||
throw new Error(`Cannot get version "${id}": ${e.message}`)
|
||||
}
|
||||
})()
|
||||
return Versions[id]
|
||||
}
|
||||
return Versions[id]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
export function isPromise(obj: any): obj is Promise<any> {
|
||||
return typeof (obj as any)?.then === 'function'
|
||||
}
|
||||
|
||||
const dec2hex = (dec: number) => ('0' + dec.toString(16)).substr(-2)
|
||||
|
||||
export function hexId(length = 12) {
|
||||
|
||||
Reference in New Issue
Block a user