This commit is contained in:
Rizky 2024-08-20 18:48:46 +07:00
parent 1d37ad45cb
commit fd4f9ee069
3 changed files with 48 additions and 47 deletions

File diff suppressed because one or more lines are too long

View File

@ -14,7 +14,7 @@ import { declareScope } from "./scope/scope";
// @ts-ignore // @ts-ignore
import { FNCompDef } from "../../../../../utils/types/meta-fn"; import { FNCompDef } from "../../../../../utils/types/meta-fn";
import { editorLocalValue } from "../../../../vi/render/script/local"; import { local_cached_value } from "../../../../vi/render/script/local";
import { propInstanceOnChange } from "../../side/prop-instance/on-change"; import { propInstanceOnChange } from "../../side/prop-instance/on-change";
import { codeEditAdvJs } from "./code-edit/adv-js"; import { codeEditAdvJs } from "./code-edit/adv-js";
import { codeEditPropInstance } from "./code-edit/prop-instance"; import { codeEditPropInstance } from "./code-edit/prop-instance";
@ -346,7 +346,7 @@ export const EdScriptMonaco: FC<{}> = () => {
scope = await code_result; scope = await code_result;
} }
} else { } else {
editorLocalValue[active.item_id] = null; local_cached_value[active.item_id] = null;
if (mode === "js") { if (mode === "js") {
const code_result = codeEditAdvJs(p, value); const code_result = codeEditAdvJs(p, value);

View File

@ -1,13 +1,13 @@
import { ReactNode, useEffect, useRef, useState } from "react"; import { ReactNode, useEffect, useRef, useState } from "react";
import { IMeta } from "../../../ed/logic/ed-global"; import { IMeta } from "../../../ed/logic/ed-global";
import { updatePropScope } from "./eval-prop";
import { modifyChild } from "./passprop";
import { VG } from "../global"; import { VG } from "../global";
import { modifyChild } from "./passprop";
export const editorLocalValue = {} as Record<string, any>; export const local_cached_value = {} as Record<string, any>;
export const createViLocal = ( export const createViLocal = (
vi: { vi: {
page: { cur: { id: string } };
layout: VG["layout"]; layout: VG["layout"];
site: { db: any; api: any }; site: { db: any; api: any };
meta: Record<string, IMeta>; meta: Record<string, IMeta>;
@ -36,9 +36,14 @@ export const createViLocal = (
const { children, parent_key } = arg; const { children, parent_key } = arg;
const init_local_effect = vi.script?.init_local_effect; const init_local_effect = vi.script?.init_local_effect;
const metas = is_layout ? vi.layout?.meta : vi.meta; const metas = is_layout ? vi.layout?.meta : vi.meta;
const ref = useRef<any>(
editorLocalValue[id] ? editorLocalValue[id] : arg.value const curid = vi.page.cur.id + "~" + id;
); if (!local_cached_value[curid]) {
local_cached_value[curid] = arg.value;
}
const ref = useRef<any>(local_cached_value[curid]);
const [_, set] = useState({}); const [_, set] = useState({});
const local = ref.current; const local = ref.current;
local.render = () => { local.render = () => {
@ -50,8 +55,6 @@ export const createViLocal = (
} }
}; };
updatePropScope(vi, meta, meta.script?.scope, parent_key);
if (arg.hook) { if (arg.hook) {
arg.hook(local); arg.hook(local);
} }
@ -76,12 +79,10 @@ export const createViLocal = (
if (typeof init_local_effect === "object") { if (typeof init_local_effect === "object") {
init_local_effect[id] = true; init_local_effect[id] = true;
} }
const fn = async () => { const fn = async () => {
if (arg.effect) { if (arg.effect) {
await arg.effect(local); await arg.effect(local);
if (isEditor) {
editorLocalValue[id] = local;
}
} }
}; };
@ -93,19 +94,19 @@ export const createViLocal = (
useEffect(() => { useEffect(() => {
if (isEditor) { if (isEditor) {
if (editorLocalValue[id] === null) { if (local_cached_value[id] === null) {
const fn = async () => { const fn = async () => {
if (arg.effect) { if (arg.effect) {
await arg.effect(local); await arg.effect(local);
if (isEditor) { if (isEditor) {
editorLocalValue[id] = local; local_cached_value[id] = local;
} }
} }
}; };
fn(); fn();
} }
} }
}, [editorLocalValue[id]]); }, [local_cached_value[id]]);
const result = modifyChild(children, { const result = modifyChild(children, {
...meta.script?.scope, ...meta.script?.scope,