From ca0737e393bbf5c45f688593bbfaf41079a66784 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Fri, 25 Aug 2023 12:14:42 +0530 Subject: feat: h expressions for declaring elements --- src/declarations.ts | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src/declarations.ts') diff --git a/src/declarations.ts b/src/declarations.ts index a82f42f..5725846 100644 --- a/src/declarations.ts +++ b/src/declarations.ts @@ -30,9 +30,40 @@ export const toDeclaration = }, Call: async ({ name, args }) => { return matchString(name, { - // h: () => { - // - // }, + h: async () => { + const [sel, map, childreExpr] = args + + // Selector + match(sel, { + Selector: sel => { + selector = sel + }, + _: _ => {}, + }) + + const props = await evalExpr(map, actions) + match(props, { + Map: props => { + for (const [key, value] of Object.entries(props)) { + properties.set(key, value) + } + }, + _: _ => {}, + }) + + const childrenExprs = await match< + Promise>, + EvalValue + >(await evalExpr(childreExpr, actions), { + Lazy: async exprs => + Promise.all(exprs.map(toDeclaration(actions))), + _: async _ => [], + }) + + children.push( + ...(childrenExprs.filter(Boolean) as Array), + ) + }, instance: async () => { isInstance = true const [sel, map] = args -- cgit v1.3.1