support for __result__ in web components and SqLambda
This commit is contained in:
parent
e2abc53200
commit
fc3a7c6cf9
|
@ -248,7 +248,7 @@ export const ExpressionViewer: React.FC<Props> = ({ value, width }) => {
|
||||||
{(_) =>
|
{(_) =>
|
||||||
value.value
|
value.value
|
||||||
.entries()
|
.entries()
|
||||||
.filter(([key, _]) => !key.match(/^(Math|System)\./))
|
.filter(([key, _]) => !key.match(/^(__result__)$/))
|
||||||
.map(([key, r]) => (
|
.map(([key, r]) => (
|
||||||
<ExpressionViewer
|
<ExpressionViewer
|
||||||
key={key}
|
key={key}
|
||||||
|
|
|
@ -18,23 +18,28 @@ export class SqLambda {
|
||||||
// Might be good to use uuid instead, but there's no way to remove sources from projects.
|
// Might be good to use uuid instead, but there's no way to remove sources from projects.
|
||||||
// So this is not thread-safe.
|
// So this is not thread-safe.
|
||||||
const callId = "__lambda__";
|
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) =>
|
const quote = (arg: string) =>
|
||||||
`"${arg.replace(new RegExp('"', "g"), '\\"')}"`;
|
`"${arg.replace(new RegExp('"', "g"), '\\"')}"`;
|
||||||
const argsSource = args
|
const argsSource = args
|
||||||
.map((arg) => (typeof arg === "number" ? arg : quote(arg)))
|
.map((arg) => (typeof arg === "number" ? arg : quote(arg)))
|
||||||
.join(",");
|
.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) =>
|
.map((item, i) =>
|
||||||
typeof item === "string" ? (i ? "." + item : item) : `[${item}]`
|
typeof item === "string" ? (i ? "." + item : item) : `[${item}]`
|
||||||
)
|
)
|
||||||
.join("");
|
.join("");
|
||||||
|
|
||||||
|
// something like: foo.bar[3].baz(1,2,3)
|
||||||
const source = `${functionNameSource}(${argsSource})`;
|
const source = `${functionNameSource}(${argsSource})`;
|
||||||
|
|
||||||
project.setSource(callId, source);
|
project.setSource(callId, source);
|
||||||
project.setContinues(callId, [sourceId]);
|
project.setContinues(callId, [sourceId]);
|
||||||
project.run(callId);
|
project.run(callId);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user