diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index 8ef540a7..b935a932 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -1,5 +1,12 @@ import * as React from "react"; -import { SqValue, environment, defaultEnvironment } from "@quri/squiggle-lang"; +import { + SqValue, + environment, + defaultEnvironment, + resultMap, + SqValueLocation, + SqValueTag, +} from "@quri/squiggle-lang"; import { useSquiggle } from "../lib/hooks"; import { SquiggleViewer } from "./SquiggleViewer"; @@ -97,28 +104,20 @@ export const SquiggleChart: React.FC = React.memo( count: diagramCount, }; + const resultToRender = resultMap(result, (value) => + value.tag === SqValueTag.Void ? bindings.asValue() : value + ); + return ( -
- -
- -
+ ); } ); diff --git a/packages/components/src/components/SquiggleViewer/utils.ts b/packages/components/src/components/SquiggleViewer/utils.ts index 5afff150..f23de043 100644 --- a/packages/components/src/components/SquiggleViewer/utils.ts +++ b/packages/components/src/components/SquiggleViewer/utils.ts @@ -18,4 +18,4 @@ export type MergedItemSettings = { }; export const locationAsString = (location: SqValueLocation) => - location.path.root + "/" + location.path.items.join("."); + location.path.items.join("."); diff --git a/packages/squiggle-lang/src/js/SqModule.ts b/packages/squiggle-lang/src/js/SqModule.ts index 24cb90b6..c50d3be3 100644 --- a/packages/squiggle-lang/src/js/SqModule.ts +++ b/packages/squiggle-lang/src/js/SqModule.ts @@ -20,4 +20,11 @@ export class SqModule { this.location ); } + + get(k: string) { + const v = RSModuleValue.get(this._value, k); + return v === undefined || v === null + ? undefined + : wrapValue(v, this.location.extend(k)); + } } 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 3d5f246d..e76acbc8 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 @@ -11,3 +11,6 @@ let toString = (v: squiggleValue_Module): string => @genType let toSquiggleValue = (v: squiggleValue_Module): squiggleValue => IEvBindings(v) + +@genType +let get = ReducerInterface_InternalExpressionValue.nameSpaceGet diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res index 00d032bf..6cd7cc81 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res @@ -239,3 +239,9 @@ let nameSpaceToKeyValuePairs = (nameSpace: nameSpace): array<(string, t)> => { let NameSpace(container) = nameSpace container->Belt.Map.String.toArray } + +let nameSpaceGet = (nameSpace: nameSpace, key: string): option => { + let NameSpace(container) = nameSpace + container->Belt.Map.String.get(key) + +}