From b7aa126e6a55d11b92584f1d5676c71db81e9caf Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Sun, 28 Aug 2022 21:45:15 +0400 Subject: [PATCH] output bindings when result is void --- .../SquiggleViewer/ExpressionViewer.tsx | 3 ++- .../components/src/lib/hooks/useSquiggle.ts | 18 +++++++++++++++--- packages/squiggle-lang/src/js/SqModule.ts | 11 +++++++++++ .../ForTS_SquiggleValue_Module.res | 4 ++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/packages/components/src/components/SquiggleViewer/ExpressionViewer.tsx b/packages/components/src/components/SquiggleViewer/ExpressionViewer.tsx index 9b554107..7ae23c1a 100644 --- a/packages/components/src/components/SquiggleViewer/ExpressionViewer.tsx +++ b/packages/components/src/components/SquiggleViewer/ExpressionViewer.tsx @@ -254,7 +254,8 @@ export const ExpressionViewer: React.FC = ({ return ( {(_) => - Object.entries(expression.value) + expression.value + .entries() .filter(([key, _]) => !key.match(/^(Math|System)\./)) .map(([key, r]) => ( { 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; }; diff --git a/packages/squiggle-lang/src/js/SqModule.ts b/packages/squiggle-lang/src/js/SqModule.ts index e6bc6be2..b241ff0d 100644 --- a/packages/squiggle-lang/src/js/SqModule.ts +++ b/packages/squiggle-lang/src/js/SqModule.ts @@ -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)); + } } diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.res index 8125d1f3..759415fe 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.res @@ -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)