support for __result__ in web components and SqLambda

This commit is contained in:
Vyacheslav Matyukhin 2022-09-01 19:11:49 +04:00
parent e2abc53200
commit fc3a7c6cf9
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
2 changed files with 13 additions and 8 deletions

View File

@ -248,7 +248,7 @@ export const ExpressionViewer: React.FC<Props> = ({ value, width }) => {
{(_) =>
value.value
.entries()
.filter(([key, _]) => !key.match(/^(Math|System)\./))
.filter(([key, _]) => !key.match(/^(__result__)$/))
.map(([key, r]) => (
<ExpressionViewer
key={key}

View File

@ -18,23 +18,28 @@ export class SqLambda {
// Might be good to use uuid instead, but there's no way to remove sources from projects.
// So this is not thread-safe.
const callId = "__lambda__";
if (this.location.path.root !== "bindings") {
return {
tag: "Error",
value: SqError.createTodoError("Only bindings lambdas can be rendered"),
};
}
const quote = (arg: string) =>
`"${arg.replace(new RegExp('"', "g"), '\\"')}"`;
const argsSource = args
.map((arg) => (typeof arg === "number" ? arg : quote(arg)))
.join(",");
const functionNameSource = this.location.path.items
// end expression values are exposed in bindings via secret `__result__` variable and we can access them through it
const pathItems = [
...(this.location.path.root === "result" ? ["__result__"] : []),
...this.location.path.items,
];
// full function name, e.g. foo.bar[3].baz
const functionNameSource = pathItems
.map((item, i) =>
typeof item === "string" ? (i ? "." + item : item) : `[${item}]`
)
.join("");
// something like: foo.bar[3].baz(1,2,3)
const source = `${functionNameSource}(${argsSource})`;
project.setSource(callId, source);
project.setContinues(callId, [sourceId]);
project.run(callId);