Upgrade @mcschema

This commit is contained in:
Misode
2020-08-06 14:02:05 +02:00
parent 84096187e7
commit 7d518526e2
3 changed files with 26 additions and 23 deletions
+17 -14
View File
@@ -2,15 +2,14 @@ import Split from 'split.js'
import {
AbstractView,
Base,
COLLECTIONS,
CollectionRegistry,
DataModel,
locale,
LOCALES,
SourceView,
TreeView,
SCHEMAS,
} from '@mcschema/core'
import '@mcschema/java-1.16'
import { getCollections, getSchemas } from '@mcschema/java-1.16'
import { RegistryFetcher } from './RegistryFetcher'
import { ErrorsView } from './ErrorsView'
import config from '../config.json'
@@ -29,17 +28,6 @@ const addChecked = (el: HTMLElement) => {
}, 2000)
}
const buildModel = (model: any) => {
if (model.schema) {
models[model.id] = new DataModel(SCHEMAS.get(model.schema))
} else if (model.children) {
model.children.forEach(buildModel)
}
}
let models: { [key: string]: DataModel } = {}
config.models.forEach(buildModel)
const treeViewObserver = (el: HTMLElement) => {
el.querySelectorAll('.node-header[data-help]').forEach(e => {
const div = document.createElement('div')
@@ -121,12 +109,27 @@ const views: {[key: string]: AbstractView} = {
'errors': new ErrorsView(dummyModel, errorsViewEl)
}
const COLLECTIONS = getCollections()
Promise.all([
fetchLocale(LOCALES.language),
...(LOCALES.language === 'en' ? [] : [fetchLocale('en')]),
RegistryFetcher(COLLECTIONS, config.registries)
]).then(responses => {
const SCHEMAS = getSchemas(COLLECTIONS)
let models: { [key: string]: DataModel } = {}
const buildModel = (model: any) => {
if (model.schema) {
models[model.id] = new DataModel(SCHEMAS.get(model.schema))
} else if (model.children) {
model.children.forEach(buildModel)
}
}
config.models.forEach(buildModel)
let selected = ''
Object.values(models).forEach(m => m.validate(true))