This commit is contained in:
Rizky 2024-06-24 17:22:57 +07:00
parent 964f0fe8ba
commit c64fe0e4d0
4 changed files with 79 additions and 70 deletions

File diff suppressed because one or more lines are too long

View File

@ -157,7 +157,7 @@ export const EDGlobal = {
script: {
site_types: {} as Record<string, string>,
loaded: false,
do_edit: async (newval: string, all?: boolean) => { },
do_edit: async (newval: string, all?: boolean) => {},
db: null as any,
api: null as any,
init_local_effect: {} as Record<string, boolean>,
@ -176,13 +176,14 @@ export const EDGlobal = {
page: EPage;
doc: DPage;
on_update?: (bin: Uint8Array, origin: any) => Promise<void>;
update_timeout: any;
}
>,
building: false,
meta: {} as Record<string, IMeta>,
entry: [] as string[],
tree: [] as NodeModel<IMeta>[],
render: () => { },
render: () => {},
},
comp: {
doc: null as null | DComp,
@ -295,9 +296,9 @@ export const EDGlobal = {
type: "item" as "item" | "prop-master" | "prop-instance" | "comp-types",
prop_kind: "" as PropFieldKind,
prop_name: "",
on_close: () => { },
on_close: () => {},
typings: { status: "ok" as "ok" | "loading" | "error", err_msg: "" },
wb_render: () => { },
wb_render: () => {},
},
site: null as null | ((site_id: string) => void | Promise<void>),
site_form: null as null | {

View File

@ -7,6 +7,7 @@ import { treeCacheBuild, treeRebuild } from "./tree/build";
import { get, set } from "idb-keyval";
import { nav } from "../../vi/render/script/extract-nav";
const UPDATE_TIMEOUT = 200;
export const edRoute = async (p: PG) => {
if (p.sync && (p.status === "ready" || p.status === "init")) {
if (!p.site.domain && !p.site.name) {
@ -67,6 +68,8 @@ export const reloadLayout = async (p: PG, layout_id: string, note: string) => {
}
page.on_update = async (bin: Uint8Array, origin: any) => {
clearTimeout(page.update_timeout);
page.update_timeout = setTimeout(async () => {
if (origin === "local" || !p.sync) return;
const res = await p.sync.yjs.sv_local(
@ -106,6 +109,7 @@ export const reloadLayout = async (p: PG, layout_id: string, note: string) => {
savePageMetaCache(p, meta_cache.meta);
}
}
}, UPDATE_TIMEOUT);
};
const root = (doc.getMap("map").get("root") as any)?.toJSON();
@ -170,6 +174,8 @@ export const reloadPage = async (
}
page.on_update = async (bin: Uint8Array, origin: any) => {
clearTimeout(page.update_timeout);
page.update_timeout = setTimeout(async () => {
if (origin === "local" || !p.sync) return;
if (page.page.id !== remotePage.id) {
@ -210,6 +216,7 @@ export const reloadPage = async (
if (active.should_render_main) p.render();
}
}, UPDATE_TIMEOUT);
};
doc.on("update", page.on_update);

View File

@ -125,6 +125,7 @@ export const devItem = (
{ value: string; valueBuilt?: string }
>;
console.log("committing", pedit);
if (mitem) {
for (const [item_id, changes] of Object.entries(pedit)) {
const meta = metas[item_id];