fix prop option + frontend recursive watch

This commit is contained in:
rizrmd 2024-06-03 11:38:50 +07:00
parent c12a14bd8a
commit 1a71697266
2 changed files with 51 additions and 32 deletions

View File

@ -108,8 +108,14 @@ export const initFrontEnd = async (
ctx: build_ctx,
timeout: null,
rebuilding: false,
watch: watch(dir.data(root), async (event, filename) => {
watch: watch(
dir.data(root),
{
recursive: true,
},
async (event, filename) => {
const fe = code.internal.frontend[id_site];
if (filename?.startsWith("node_modules")) return;
if (
fe &&
(filename?.endsWith(".tsx") ||
@ -123,7 +129,8 @@ export const initFrontEnd = async (
fe.rebuilding = false;
}
}
}),
}
),
};
const fe = code.internal.frontend[id_site];
fe.rebuilding = true;

View File

@ -41,6 +41,7 @@ export const EdPropInstanceOptions: FC<{
width: 0,
},
options: [] as MetaOption[],
optDeps: [] as any[],
});
const p = useGlobal(EDGlobal, "EDITOR");
@ -116,7 +117,14 @@ export const EdPropInstanceOptions: FC<{
const resOpt = ${src.endsWith(";") ? src : `${src};`}
if (typeof resOpt === 'function') local.metaFn = resOpt;
else local.options = resOpt;
else {
if (typeof resOpt === 'object' && Array.isArray(resOpt.deps) && typeof resOpt.fn === 'function') {
local.metaFn = resOpt.fn;
local.optDeps = resOpt.deps;
} else {
local.options = resOpt;
}
}
} catch(e) { console.error(e); }`;
fn = new Function(...Object.keys(arg), "local", final);
fn(...Object.values(arg), local);
@ -127,7 +135,10 @@ export const EdPropInstanceOptions: FC<{
} else {
local.options = local.loaded;
}
}
useEffect(() => {
if (local.metaFn) {
if (local.metaFn && !local.loaded && !local.loading) {
local.loading = true;
try {
@ -147,6 +158,7 @@ export const EdPropInstanceOptions: FC<{
}
}
}
}, local.optDeps);
let evalue: any = null;
try {