From 02466acc4b768ba3f9fce23acadd0c543db512b4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 18 Oct 2020 12:55:26 +0900 Subject: Fix page bug --- src/client/scripts/hpml/evaluator.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/client/scripts/hpml') diff --git a/src/client/scripts/hpml/evaluator.ts b/src/client/scripts/hpml/evaluator.ts index 01a122c0e4..bd7ec600cd 100644 --- a/src/client/scripts/hpml/evaluator.ts +++ b/src/client/scripts/hpml/evaluator.ts @@ -7,6 +7,7 @@ import { createAiScriptEnv } from '../aiscript/api'; import { collectPageVars } from '../collect-page-vars'; import { initLib } from './lib'; import * as os from '@/os'; +import { markRaw, ref, Ref } from 'vue'; type Fn = { slots: string[]; @@ -23,7 +24,7 @@ export class Hpml { public aiscript?: AiScript; private pageVarUpdatedCallback; public canvases: Record = {}; - public vars: Record; + public vars: Ref> = ref({}); public page: Record; private opts: { @@ -38,7 +39,7 @@ export class Hpml { this.opts = opts; if (this.opts.enableAiScript) { - this.aiscript = new AiScript({ ...createAiScriptEnv({ + this.aiscript = markRaw(new AiScript({ ...createAiScriptEnv({ storageKey: 'pages:' + this.page.id }), ...initLib(this)}, { in: (q) => { @@ -56,7 +57,7 @@ export class Hpml { }, log: (type, params) => { }, - }); + })); this.aiscript.scope.opts.onUpdated = (name, value) => { this.eval(); @@ -89,7 +90,7 @@ export class Hpml { @autobind public eval() { try { - this.vars = this.evaluateVars(); + this.vars.value = this.evaluateVars(); } catch (e) { //this.onError(e); } @@ -99,7 +100,7 @@ export class Hpml { public interpolate(str: string) { if (str == null) return null; return str.replace(/{(.+?)}/g, match => { - const v = this.vars ? this.vars[match.slice(1, -1).trim()] : null; + const v = this.vars[match.slice(1, -1).trim()]; return v == null ? 'NULL' : v.toString(); }); } -- cgit v1.2.3-freya