From 489a6e4bb463a35e1a8250abb51a12873767cd32 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 18 Mar 2020 00:42:37 -0400 Subject: [PATCH] Store the trace and value as state in LineView. --- src/FormView.tsx | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/FormView.tsx b/src/FormView.tsx index b9cede6..aa2c1c5 100644 --- a/src/FormView.tsx +++ b/src/FormView.tsx @@ -3,10 +3,11 @@ // version 3.0. The full text of the license can be found in LICENSE.txt. // SPDX-License-Identifier: GPL-3.0-only -import { createDependentEffect, createMemo, createState } from 'solid-js'; +import { createEffect, createMemo, createState } from 'solid-js'; import { For, Show } from 'solid-js/dom'; import { TaxReturn, Form, Line } from 'ustaxlib/core'; -import { Edge, getLastTraceList } from 'ustaxlib/core/Trace'; +import * as Trace from 'ustaxlib/core/Trace'; +import { Edge } from 'ustaxlib/core/Trace'; import { graphviz } from 'd3-graphviz'; const S = require('./FormView.css'); @@ -43,20 +44,36 @@ interface LineProps { function LineView(props: LineProps) { const { tr, line } = props; - const value = createMemo(() => { - try { - return JSON.stringify(line.value(tr), null, 1); - } catch (e) { - return {e.message}; - } - }); const [ state, setState ] = createState({ + value: undefined as any, + error: undefined as any, trace: [] as readonly Edge[], showTrace: false }); - createDependentEffect(() => setState('trace', getLastTraceList()), [value]); + createEffect(() => { + const newState = { + value: undefined, + error: undefined, + trace: [] as readonly Edge[] + }; + try { + Trace.reset(); + newState.value = line.value(tr); + } catch (e) { + newState.error = e; + } + newState.trace = Trace.getLastTraceList(); + setState(newState); + }); + + const valueDisplay = createMemo(() => { + if (state.error) { + return {state.error.message}; + } + return JSON.stringify(state.value, null, 1); + }); const toggleTrace = () => setState('showTrace', !state.showTrace); @@ -68,7 +85,7 @@ function LineView(props: LineProps) { {line.description} -
{value()}
+
{valueDisplay()}
setState('showTrace', false)} /> -- 2.43.5