diff --git a/app/srv/ws/sync/sync-handler.ts b/app/srv/ws/sync/sync-handler.ts index 2feafc95..a955557f 100644 --- a/app/srv/ws/sync/sync-handler.ts +++ b/app/srv/ws/sync/sync-handler.ts @@ -85,13 +85,11 @@ export const syncHandler: WebSocketHandler = { if (baseAction) { const action = baseAction.bind(conn); - ws.sendBinary( - packr.pack({ - type: SyncType.ActionResult, - argid: msg.argid, - val: await action(...msg.args), - }) - ); + sendWS(ws, { + type: SyncType.ActionResult, + argid: msg.argid, + val: await action(...msg.args), + }); } } } diff --git a/app/web/src/nova/view/render/meta/script.tsx b/app/web/src/nova/view/render/meta/script.tsx index be1d6f78..e5937826 100644 --- a/app/web/src/nova/view/render/meta/script.tsx +++ b/app/web/src/nova/view/render/meta/script.tsx @@ -198,6 +198,8 @@ export const ViewMetaScript: FC<{ console.warn(`Available var:`, args, `\n\n`); }); } + + return output.jsx; } }; diff --git a/app/web/src/nova/view/render/meta/script/create-pass-prop.tsx b/app/web/src/nova/view/render/meta/script/create-pass-prop.tsx index ec2d38ec..ce257a39 100644 --- a/app/web/src/nova/view/render/meta/script/create-pass-prop.tsx +++ b/app/web/src/nova/view/render/meta/script/create-pass-prop.tsx @@ -1,6 +1,7 @@ import { ReactNode } from "react"; import { VG } from "../../../logic/global"; import { modifyChildScopeIndex } from "./mod-scope-index"; +import hash_sum from "hash-sum"; export const createPassProp = ( v: VG, @@ -10,15 +11,25 @@ export const createPassProp = ( return (arg: Record & { children: ReactNode; idx?: any }) => { const meta = v.meta[id]; - if (typeof arg.idx !== "undefined" && meta && meta.item && meta.item.id) { - meta.indexed_scope[arg.idx] = {}; + if (meta && meta.item && meta.item.id) { + let idx = arg.idx; + if (!idx) { + const narg: any = {}; + for (const [k, v] of Object.entries(arg)) { + if (typeof v !== "object" && typeof v !== "function") { + narg[k] = v; + } + } + idx = hash_sum(narg); + } + meta.indexed_scope[idx] = {}; for (const [k, v] of Object.entries(arg)) { if (k === "children") continue; - meta.indexed_scope[arg.idx][k] = v; + meta.indexed_scope[idx][k] = v; } - const scopeIndex = { ...existingScopeIndex, [meta.item.id]: arg.idx }; + const scopeIndex = { ...existingScopeIndex, [meta.item.id]: idx }; if (!meta.scope) { meta.scope = {}; @@ -38,6 +49,7 @@ export const createPassProp = ( if (k === "children") continue; meta.scope[k] = v; } + return arg.children; }; }; diff --git a/app/web/src/nova/view/render/meta/script/merge-upward.tsx b/app/web/src/nova/view/render/meta/script/merge-upward.tsx index 190ee3ff..31e2d3ff 100644 --- a/app/web/src/nova/view/render/meta/script/merge-upward.tsx +++ b/app/web/src/nova/view/render/meta/script/merge-upward.tsx @@ -31,6 +31,7 @@ export const mergeScopeUpwards = ( if (indexedScope || cur.scope || cur.propval) { scope = { ...cur.scope, ...indexedScope, ...cur.propval }; + for (const [k, v] of Object.entries(scope)) { if (typeof finalScope[k] === "undefined") finalScope[k] = v; } diff --git a/app/web/src/nova/view/render/meta/script/mod-scope-index.ts b/app/web/src/nova/view/render/meta/script/mod-scope-index.ts deleted file mode 100644 index 1417d535..00000000 --- a/app/web/src/nova/view/render/meta/script/mod-scope-index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { ReactNode } from "react"; - -export const modifyChildScopeIndex = ( - child: ReactNode | ReactNode[], - _scopeIndex: Record -) => { - if (Array.isArray(child)) { - const childs: any[] = []; - for (const c of child) { - childs.push(modifyChildScopeIndex(c, _scopeIndex)); - } - return childs; - } - if (typeof child === "object" && child) { - return { ...child, props: { ...(child as any).props, _scopeIndex } }; - } - return child; -}; diff --git a/app/web/src/nova/view/render/meta/script/mod-scope-index.tsx b/app/web/src/nova/view/render/meta/script/mod-scope-index.tsx new file mode 100644 index 00000000..94e4e9b4 --- /dev/null +++ b/app/web/src/nova/view/render/meta/script/mod-scope-index.tsx @@ -0,0 +1,27 @@ +import { Fragment, ReactNode } from "react"; + +export const modifyChildScopeIndex = ( + child: ReactNode | ReactNode[], + scopeIndex: Record +) => { + if (Array.isArray(child)) { + const childs: any[] = []; + for (const c of child) { + childs.push(modifyChildScopeIndex(c, scopeIndex)); + } + return childs; + } + + if (typeof child === "object" && child) { + const c = child as any; + if (c.type === Fragment) { + return ( + + {modifyChildScopeIndex(c.props.children, scopeIndex)} + + ); + } + return { ...child, props: { ...(child as any).props, scopeIndex } }; + } + return child; +}; diff --git a/pkgs/core/server/create.ts b/pkgs/core/server/create.ts index 9c3a4318..309eedad 100644 --- a/pkgs/core/server/create.ts +++ b/pkgs/core/server/create.ts @@ -17,7 +17,7 @@ export const cache = { }; export type WSData = { url: URL }; - + export const createServer = async () => { g.router = createRouter({ strictTrailingSlash: false }); @@ -32,7 +32,7 @@ export const createServer = async () => { maxPayloadLength: 9999999, closeOnBackpressureLimit: true, drain(ws) { - console.log("Backpressure relieved..."); + // console.log("Backpressure relieved..."); }, close(ws, code, reason) { const pathname = ws.data.url.pathname;