This commit is contained in:
Rizky 2024-01-27 17:28:25 +07:00
parent d997fbbaaa
commit 5d946f53a1
2 changed files with 26 additions and 21 deletions

View File

@ -106,7 +106,7 @@ export const page_load: SAction["page"]["load"] = async function (
url: page.url,
name: page.name,
snapshot: await gzipAsync(bin),
comps: await prepareComponentForPage(id, this, false),
comps: (await prepareComponentForPage(id, this, false)) || {},
};
}
} else if (snap && !ydoc) {
@ -140,7 +140,7 @@ export const page_load: SAction["page"]["load"] = async function (
url: snap.url,
name: snap.name,
snapshot: await gzipAsync(snap.bin),
comps,
comps: comps || {},
};
} else if (snap && ydoc) {
user.active.add({
@ -156,7 +156,7 @@ export const page_load: SAction["page"]["load"] = async function (
url: snap.url,
name: snap.name,
snapshot: await gzipAsync(snap.bin),
comps: await prepareComponentForPage(id, this, true),
comps: (await prepareComponentForPage(id, this, true)) || {},
};
}
};

View File

@ -16,26 +16,31 @@ export const prepareComponentForPage = async (
const _doc = doc ? doc : docs.page[page_id].doc;
const root = _doc.getMap("map").get("root")?.toJSON() as IRoot;
const result = {} as Record<string, EComp>;
if (root) {
const result = {} as Record<string, EComp>;
if (reload_components) {
root.component_ids = await loadCompForPage(root, sync);
if (doc) {
_doc.getMap("map").get("root")?.set("component_ids", root.component_ids);
}
}
if (root.component_ids) {
for (const id of root.component_ids) {
if (!docs.comp[id]) {
await loadComponent(id, sync);
}
const snap = snapshot.get("comp", id);
if (snap) {
result[id] = { id, snapshot: await gzipAsync(snap.bin) };
if (reload_components) {
root.component_ids = await loadCompForPage(root, sync);
if (doc) {
_doc
.getMap("map")
.get("root")
?.set("component_ids", root.component_ids);
}
}
}
return result;
if (root.component_ids) {
for (const id of root.component_ids) {
if (!docs.comp[id]) {
await loadComponent(id, sync);
}
const snap = snapshot.get("comp", id);
if (snap) {
result[id] = { id, snapshot: await gzipAsync(snap.bin) };
}
}
}
return result;
}
};