__result__ variable in bindings

This commit is contained in:
Umur Ozkul 2022-09-01 14:51:20 +02:00
parent 82a4e52384
commit 7eef1d30f3
6 changed files with 19 additions and 13 deletions

View File

@ -16,7 +16,9 @@ let runFetchResult = (project, sourceId) => {
let runFetchFlatBindings = (project, sourceId) => { let runFetchFlatBindings = (project, sourceId) => {
Project.run(project, sourceId) Project.run(project, sourceId)
Project.getBindings(project, sourceId)->InternalExpressionValue.toStringBindings Project.getBindings(project, sourceId)
->Bindings.removeResult
->InternalExpressionValue.toStringBindings
} }
test("setting continuation", () => { test("setting continuation", () => {

View File

@ -46,12 +46,12 @@ Case "Running a single source".
Getting None means you have forgotten to run the source. Getting None means you have forgotten to run the source.
*/ */
let result = project->Project.getResult("main") let result = project->Project.getResult("main")
let bindings = project->Project.getBindings("main") let bindings = project->Project.getBindings("main")->Bindings.removeResult
/* Let's display the result and bindings */ /* Let's display the result and bindings */
( (
result->InternalExpressionValue.toStringResult, result->InternalExpressionValue.toStringResult,
bindings->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, bindings->InternalExpressionValue.toStringBindings,
)->expect == ("Ok(3)", "@{}") )->expect == ("Ok(3)", "@{}")
/* You've got 3 with empty bindings. */ /* You've got 3 with empty bindings. */
}) })
@ -61,7 +61,7 @@ Case "Running a single source".
Project.setSource(project, "main", "1 + 2") Project.setSource(project, "main", "1 + 2")
Project.runAll(project) Project.runAll(project)
let result = Project.getResult(project, "main") let result = Project.getResult(project, "main")
let bindings = Project.getBindings(project, "main") let bindings = Project.getBindings(project, "main")->Bindings.removeResult
/* Now you have external bindings and external result. */ /* Now you have external bindings and external result. */
( (
result->InternalExpressionValue.toStringResult, result->InternalExpressionValue.toStringResult,
@ -89,7 +89,7 @@ Case "Running a single source".
let (result, bindings) = Project.evaluate("1+2") let (result, bindings) = Project.evaluate("1+2")
( (
result->InternalExpressionValue.toStringResult, result->InternalExpressionValue.toStringResult,
bindings->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, bindings->Bindings.removeResult->InternalExpressionValue.toStringBindings,
)->expect == ("Ok(3)", "@{}") )->expect == ("Ok(3)", "@{}")
}) })
}) })

View File

@ -29,11 +29,11 @@ describe("ReducerProject Tutorial", () => {
/* And let's check the result and bindings of source3 */ /* And let's check the result and bindings of source3 */
let result3 = Project.getResult(project, "source3") let result3 = Project.getResult(project, "source3")
let bindings3 = Project.getBindings(project, "source3") let bindings3 = Project.getBindings(project, "source3")->Bindings.removeResult
( (
result3->InternalExpressionValue.toStringResult, result3->InternalExpressionValue.toStringResult,
bindings3->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, bindings3->InternalExpressionValue.toStringBindings,
)->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}") )->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}")
}) })
@ -55,11 +55,11 @@ describe("ReducerProject Tutorial", () => {
/* And let's check the result and bindings of source3 */ /* And let's check the result and bindings of source3 */
let result3 = Project.getResult(project, "source3") let result3 = Project.getResult(project, "source3")
let bindings3 = Project.getBindings(project, "source3") let bindings3 = Project.getBindings(project, "source3")->Bindings.removeResult
( (
result3->InternalExpressionValue.toStringResult, result3->InternalExpressionValue.toStringResult,
bindings3->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, bindings3->InternalExpressionValue.toStringBindings,
)->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}") )->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}")
}) })
@ -91,11 +91,11 @@ describe("ReducerProject Tutorial", () => {
This time you are getting all the variables because we are including the other sources This time you are getting all the variables because we are including the other sources
Behind the scenes parseIncludes is setting the dependencies */ Behind the scenes parseIncludes is setting the dependencies */
let result3 = Project.getResult(project, "source3") let result3 = Project.getResult(project, "source3")
let bindings3 = Project.getBindings(project, "source3") let bindings3 = Project.getBindings(project, "source3")->Bindings.removeResult
( (
result3->InternalExpressionValue.toStringResult, result3->InternalExpressionValue.toStringResult,
bindings3->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, bindings3->InternalExpressionValue.toStringBindings,
)->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}") )->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}")
/* /*
Doing it like this is too verbose for a storybook Doing it like this is too verbose for a storybook

View File

@ -147,7 +147,7 @@ Here we will finally proceed to a real life scenario. */
test("recursive includes", () => { test("recursive includes", () => {
( (
result->InternalExpressionValue.toStringResult, result->InternalExpressionValue.toStringResult,
bindings->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, bindings->Bindings.removeResult->InternalExpressionValue.toStringBindings,
)->expect == ("Ok(6)", "@{doubleX: 2,x: 1,y: 2,z: 3}") )->expect == ("Ok(6)", "@{doubleX: 2,x: 1,y: 2,z: 3}")
/* Everything as expected */ /* Everything as expected */
}) })

View File

@ -183,3 +183,7 @@ let chainTo = (nameSpace: t, previousNameSpaces: array<t>) => {
mergeFrom(prevNameSpace, topNameSpace) mergeFrom(prevNameSpace, topNameSpace)
) )
} }
let removeResult = (NameSpace(container): t): t => {
container->Belt.Map.String.remove("__result__")->NameSpace
}

View File

@ -104,7 +104,7 @@ let callInternal = (
let doDumpBindings = (continuation: nameSpace, value: internalExpressionValue) => { let doDumpBindings = (continuation: nameSpace, value: internalExpressionValue) => {
// let _ = Continuation.inspect(continuation, "doDumpBindings") // let _ = Continuation.inspect(continuation, "doDumpBindings")
accessors.states.continuation = continuation accessors.states.continuation = continuation->Bindings.set("__result__", value)
value->Ok value->Ok
} }