From 18a60b5f53cdff3f2b9c8cecd3f34cadc6f08865 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Fri, 18 Aug 2023 11:02:34 +0530 Subject: feat: call arbitrary method on node + added :parent selector --- src/eval.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/eval.ts') diff --git a/src/eval.ts b/src/eval.ts index 445cb8f..aba31df 100644 --- a/src/eval.ts +++ b/src/eval.ts @@ -31,6 +31,11 @@ export interface EvalActions { }): Promise addChildren(id: string, children: Expr[]): Promise removeElement(id: string | undefined): Promise + callMethod( + id: string | undefined, + method: string, + args: EvalValue[], + ): Promise // calculate ?? } @@ -154,6 +159,14 @@ const getFunctions = (name: string, args: Expr[], actions: EvalActions) => { actions.removeElement( (args[0] && (await evalExpr(args[0], actions))) ?? undefined, ), + call: async () => { + const [id, method, ...methodArgs] = await Promise.all( + args.map(a => evalExpr(a, actions)), + ) + if (id && method) { + actions.callMethod(id, method, methodArgs) + } + }, _: () => Promise.reject(new Error('not supposed to be here')), }) -- cgit v1.3.1