From 6e4850d5a906c00e7623c2e5854a13e99d1e4b26 Mon Sep 17 00:00:00 2001 From: Misode Date: Fri, 24 Sep 2021 03:47:15 +0200 Subject: [PATCH] Memoize list entries and wrap model data --- package-lock.json | 14 +++++++------- package.json | 2 +- src/app/Schemas.ts | 3 ++- src/app/components/SourcePanel.tsx | 5 ++--- src/app/pages/Generator.tsx | 7 +++---- src/app/schema/renderHtml.tsx | 26 +++++++++++++++----------- src/app/schema/transformOutput.ts | 2 +- 7 files changed, 31 insertions(+), 28 deletions(-) diff --git a/package-lock.json b/package-lock.json index cb774bab..c77680a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "@mcschema/core": "^0.12.7", + "@mcschema/core": "^0.12.8", "@mcschema/java-1.15": "^0.2.0", "@mcschema/java-1.16": "^0.6.3", "@mcschema/java-1.17": "^0.2.23", @@ -315,9 +315,9 @@ } }, "node_modules/@mcschema/core": { - "version": "0.12.7", - "resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.12.7.tgz", - "integrity": "sha512-5YUeH4ywsGgIGI6fRB7jCmclMxrep1z9A1YwyT9VUYGK8CR8oCZzZ6/5Oz1IoRBS1FTLzmzbluxaN1tkxyffXQ==" + "version": "0.12.8", + "resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.12.8.tgz", + "integrity": "sha512-O7NdYlxBFgK+iH9IE4/A8JX9ESPlxZsGke66NBQ/lFIdMYMOKpTeJBk6SKgEHSneqinf9w3IXGaE3aqDeJMo6A==" }, "node_modules/@mcschema/java-1.15": { "version": "0.2.1", @@ -2790,9 +2790,9 @@ } }, "@mcschema/core": { - "version": "0.12.7", - "resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.12.7.tgz", - "integrity": "sha512-5YUeH4ywsGgIGI6fRB7jCmclMxrep1z9A1YwyT9VUYGK8CR8oCZzZ6/5Oz1IoRBS1FTLzmzbluxaN1tkxyffXQ==" + "version": "0.12.8", + "resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.12.8.tgz", + "integrity": "sha512-O7NdYlxBFgK+iH9IE4/A8JX9ESPlxZsGke66NBQ/lFIdMYMOKpTeJBk6SKgEHSneqinf9w3IXGaE3aqDeJMo6A==" }, "@mcschema/java-1.15": { "version": "0.2.1", diff --git a/package.json b/package.json index 9b5b902d..a655499a 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "author": "Misode", "license": "MIT", "dependencies": { - "@mcschema/core": "^0.12.7", + "@mcschema/core": "^0.12.8", "@mcschema/java-1.15": "^0.2.0", "@mcschema/java-1.16": "^0.6.3", "@mcschema/java-1.17": "^0.2.23", diff --git a/src/app/Schemas.ts b/src/app/Schemas.ts index e0705531..66b7b9ea 100644 --- a/src/app/Schemas.ts +++ b/src/app/Schemas.ts @@ -75,13 +75,14 @@ export async function getModel(version: VersionId, id: string): Promise { try { const data = JSON.parse(source.current.value) - model?.reset(data, false) + model?.reset(DataModel.wrapLists(data), false) } catch (e) { onError(`Error importing: ${message(e)}`) console.error(e) diff --git a/src/app/pages/Generator.tsx b/src/app/pages/Generator.tsx index b7db25ae..c09a1653 100644 --- a/src/app/pages/Generator.tsx +++ b/src/app/pages/Generator.tsx @@ -1,5 +1,4 @@ -import type { DataModel } from '@mcschema/core' -import { Path } from '@mcschema/core' +import { DataModel, Path } from '@mcschema/core' import { getCurrentUrl } from 'preact-router' import { useEffect, useErrorBoundary, useRef, useState } from 'preact/hooks' import config from '../../config.json' @@ -63,7 +62,7 @@ export function Generator({ lang, changeTitle, version, onChangeVersion }: Gener const reset = () => { Analytics.generatorEvent('reset') - model?.reset(model.schema.default(), true) + model?.reset(DataModel.wrapLists(model.schema.default()), true) } const undo = (e: MouseEvent) => { e.stopPropagation() @@ -118,7 +117,7 @@ export function Generator({ lang, changeTitle, version, onChangeVersion }: Gener preset.generator.biome_source.seed = seed } } - model?.reset(preset, false) + model?.reset(DataModel.wrapLists(preset), false) }) } diff --git a/src/app/schema/renderHtml.tsx b/src/app/schema/renderHtml.tsx index 41a3ccf0..2ca471e5 100644 --- a/src/app/schema/renderHtml.tsx +++ b/src/app/schema/renderHtml.tsx @@ -61,7 +61,7 @@ export const renderHtml: RenderHook = { const choiceContextPath = config?.choiceContext ? new Path([], [config.choiceContext]) : config?.context ? new Path([], [config.context]) : path const set = (value: string) => { const c = choices.find(c => c.type === value) ?? choice - path.model.set(path, c.change ? c.change(value) : c.node.default()) + path.model.set(path, c.change ? c.change(value, { wrapLists: true }) : DataModel.wrapLists(c.node.default())) } const inject =