output bindings when result is void
This commit is contained in:
parent
481483e937
commit
b7aa126e6a
|
@ -254,7 +254,8 @@ export const ExpressionViewer: React.FC<Props> = ({
|
|||
return (
|
||||
<VariableList path={path} heading="Module">
|
||||
{(_) =>
|
||||
Object.entries(expression.value)
|
||||
expression.value
|
||||
.entries()
|
||||
.filter(([key, _]) => !key.match(/^(Math|System)\./))
|
||||
.map(([key, r]) => (
|
||||
<ExpressionViewer
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
import { environment, run, SqValue } from "@quri/squiggle-lang";
|
||||
import {
|
||||
environment,
|
||||
resultMap,
|
||||
run,
|
||||
SqValue,
|
||||
SqValueTag,
|
||||
} from "@quri/squiggle-lang";
|
||||
import { useEffect, useMemo } from "react";
|
||||
|
||||
type SquiggleArgs = {
|
||||
|
@ -12,8 +18,12 @@ type SquiggleArgs = {
|
|||
export const useSquiggle = (args: SquiggleArgs) => {
|
||||
const result = useMemo(
|
||||
() => {
|
||||
const { result } = run(args.code, { environment: args.environment });
|
||||
return result;
|
||||
const { result, bindings } = run(args.code, {
|
||||
environment: args.environment,
|
||||
});
|
||||
return resultMap(result, (v) =>
|
||||
v.tag === SqValueTag.Void ? bindings.asValue() : v
|
||||
);
|
||||
},
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[
|
||||
|
@ -30,5 +40,7 @@ export const useSquiggle = (args: SquiggleArgs) => {
|
|||
onChange?.(result.tag === "Ok" ? result.value : undefined);
|
||||
}, [result, onChange]);
|
||||
|
||||
console.log(result);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as RSModuleValue from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.gen";
|
||||
import { SqModuleValue, wrapValue } from "./SqValue";
|
||||
|
||||
export class SqModule {
|
||||
_value: RSModuleValue.squiggleValue_Module;
|
||||
|
@ -6,4 +7,14 @@ export class SqModule {
|
|||
constructor(_value: RSModuleValue.squiggleValue_Module) {
|
||||
this._value = _value;
|
||||
}
|
||||
|
||||
entries() {
|
||||
return RSModuleValue.getKeyValuePairs(this._value).map(
|
||||
([k, v]) => [k, wrapValue(v)] as const
|
||||
);
|
||||
}
|
||||
|
||||
asValue() {
|
||||
return new SqModuleValue(RSModuleValue.toSquiggleValue(this._value));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,3 +8,7 @@ let getKeyValuePairs = (v: squiggleValue_Module): array<(string, squiggleValue)>
|
|||
@genType
|
||||
let toString = (v: squiggleValue_Module): string =>
|
||||
ReducerInterface_InternalExpressionValue.toStringNameSpace(v)
|
||||
|
||||
@genType
|
||||
let toSquiggleValue = (v: squiggleValue_Module): squiggleValue =>
|
||||
IEvBindings(v)
|
||||
|
|
Loading…
Reference in New Issue
Block a user