wip comp load
This commit is contained in:
parent
00a242cfea
commit
7eaf89b318
|
|
@ -3,7 +3,7 @@ import babel from "recast/parsers/babel-ts";
|
|||
|
||||
export type ParsedScope = Exclude<ReturnType<typeof parseJs>, undefined>;
|
||||
|
||||
export const parseJs = (code?: string) => {
|
||||
export const parseJs = (code?: string, show_error?: boolean) => {
|
||||
if (!code) return undefined;
|
||||
const local = { name: "", value: "", start: 0, end: 0 };
|
||||
const passprop: Record<
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { GenMetaP } from "../../../../web/src/nova/vi/utils/types";
|
|||
import { IItem } from "../../../../web/src/utils/types/item";
|
||||
import { IRoot } from "../../../../web/src/utils/types/root";
|
||||
import { docs } from "../entity/docs";
|
||||
import { snapshot } from "../entity/snapshot";
|
||||
import { SyncConnection } from "../type";
|
||||
import { loadComponent, userSyncComponent } from "./load-component";
|
||||
import { parseJs } from "./parser/parse-js";
|
||||
|
|
@ -49,6 +50,7 @@ export const loadCompForPage = async (ctree: IRoot, sync: SyncConnection) => {
|
|||
const mcomps: GenMetaP["comps"] = {};
|
||||
const result = new Set<string>();
|
||||
const loading = {} as Record<string, Promise<void>>;
|
||||
const should_save = {} as Record<string, IItem>;
|
||||
for (const child of ctree.childs) {
|
||||
await initLoadComp(
|
||||
{ comps: mcomps, meta, mode: "page" },
|
||||
|
|
@ -56,11 +58,12 @@ export const loadCompForPage = async (ctree: IRoot, sync: SyncConnection) => {
|
|||
{
|
||||
visit(meta, item, shared) {
|
||||
if (item.adv?.js) {
|
||||
const script = parseJs(item.adv.js);
|
||||
|
||||
let script = undefined;
|
||||
script = parseJs(item.adv.js);
|
||||
if (
|
||||
!item.script ||
|
||||
Object.keys(script || {}) !== Object.keys(item.script || {})
|
||||
Object.keys(script || {}).length !==
|
||||
Object.keys(item.script || {}).length
|
||||
) {
|
||||
shared.should_save = true;
|
||||
item.script = script;
|
||||
|
|
@ -69,12 +72,7 @@ export const loadCompForPage = async (ctree: IRoot, sync: SyncConnection) => {
|
|||
},
|
||||
async done(shared) {
|
||||
if (shared.should_save && shared.root.component?.id) {
|
||||
// await db.component.update({
|
||||
// where: { id: shared.root.component.id },
|
||||
// data: {
|
||||
// content_tree: shared.root,
|
||||
// },
|
||||
// });
|
||||
should_save[shared.root.component.id] = shared.root;
|
||||
}
|
||||
},
|
||||
load: async (comp_ids) => {
|
||||
|
|
@ -101,5 +99,20 @@ export const loadCompForPage = async (ctree: IRoot, sync: SyncConnection) => {
|
|||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (Object.keys(should_save).length > 0) {
|
||||
for (const [comp_id, v] of Object.entries(should_save)) {
|
||||
await db.component.update({
|
||||
where: { id: comp_id },
|
||||
data: {
|
||||
content_tree: v,
|
||||
name: v.name,
|
||||
},
|
||||
});
|
||||
await snapshot.del("comp", comp_id);
|
||||
delete docs.comp[comp_id];
|
||||
await loadComponent(comp_id, sync);
|
||||
}
|
||||
}
|
||||
return [...result];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -86,6 +86,10 @@ export const snapshot = {
|
|||
return res as DocSnapshot;
|
||||
},
|
||||
|
||||
async del<K extends DocSnapshot["type"]>(type: K, id: string) {
|
||||
await this.db.remove(`${type}-${id}`);
|
||||
},
|
||||
|
||||
get<K extends DocSnapshot["type"]>(type: K, id: string) {
|
||||
return this.db.get(`${type}-${id}`) as DocSnapshotMap[K] | null;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import { parseJs } from "../../../../../../srv/ws/sync/editor/parser/parse-js";
|
||||
import { IContent } from "../../../../utils/types/general";
|
||||
import { IItem } from "../../../../utils/types/item";
|
||||
import { GenMetaP, IMeta } from "../../utils/types";
|
||||
import { genMeta } from "../meta";
|
||||
|
|
|
|||
Loading…
Reference in New Issue