From 5dcb8d823904e506cf034be2f7c1f3fa4f1b5223 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 22 Feb 2024 07:20:52 +0100 Subject: [PATCH] improve app reactivity with onDemandOnly --- .../apps/components/helpers/InputValue.svelte | 16 ++++++++++------ .../apps/components/helpers/ResolveConfig.svelte | 2 ++ .../components/helpers/RunnableComponent.svelte | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/frontend/src/lib/components/apps/components/helpers/InputValue.svelte b/frontend/src/lib/components/apps/components/helpers/InputValue.svelte index 423ac9bbc1..3166d56249 100644 --- a/frontend/src/lib/components/apps/components/helpers/InputValue.svelte +++ b/frontend/src/lib/components/apps/components/helpers/InputValue.svelte @@ -30,6 +30,7 @@ export let key: string = '' export let field: string = key export let onDemandOnly: boolean = false + export let exportValueFunction: boolean = false const { componentControl, runnableComponents } = getContext('AppViewerContext') @@ -98,11 +99,7 @@ const debounce_ms = 50 export async function computeExpr(args?: Record) { - const nvalue = await evalExpr(lastInput as EvalAppInput, args) - if (!deepEqual(nvalue, value)) { - value = nvalue - } - return nvalue + return await evalExpr(lastInput as EvalAppInput, args) } function debounce(cb: () => Promise) { @@ -134,6 +131,7 @@ const debounceTemplate = async () => { let nvalue = await getValue(lastInput as EvalAppInput) if (!deepEqual(nvalue, value)) { + // console.log('template') value = nvalue } } @@ -157,9 +155,11 @@ return x }) } + if (!onDemandOnly) { let nhash = typeof nvalue != 'object' ? nvalue : sum(nvalue) if (lastExprHash != nhash) { + // console.log('eval changed', field, nvalue) value = nvalue lastExprHash = nhash } @@ -172,6 +172,7 @@ $: lastInput?.type == 'templatev2' && lastInput.eval && debounceTemplate() async function handleConnection() { + // console.log('handleCon') if (lastInput?.type === 'connected') { if (lastInput.connection) { const { path, componentId } = lastInput.connection @@ -195,7 +196,8 @@ } else if (lastInput?.type == 'eval') { value = await evalExpr(lastInput as EvalAppInput) } else if (lastInput?.type == 'evalv2') { - if (onDemandOnly) { + // console.log('evalv2', onDemandOnly, field) + if (onDemandOnly && exportValueFunction) { value = (args?: any) => { return evalExpr(lastInput as EvalV2AppInput, args) } @@ -320,6 +322,8 @@ return } + // console.log('onValueChange', newValue, connection, previousConnectedValue) + previousConnectedValue = newValue let { path }: { path: string } = connection diff --git a/frontend/src/lib/components/apps/components/helpers/ResolveConfig.svelte b/frontend/src/lib/components/apps/components/helpers/ResolveConfig.svelte index 222cb1f4e6..af8412662f 100644 --- a/frontend/src/lib/components/apps/components/helpers/ResolveConfig.svelte +++ b/frontend/src/lib/components/apps/components/helpers/ResolveConfig.svelte @@ -29,6 +29,7 @@ bind:value={resolvedConfig.configuration[choice][nestedKey]} onDemandOnly={initialConfig?.type == 'oneOf' && initialConfig?.configuration?.[choice]?.[nestedKey]?.onDemandOnly} + exportValueFunction /> {/if} {/each} @@ -41,5 +42,6 @@ onDemandOnly={(initialConfig?.type == 'static' || initialConfig?.type == 'evalv2') && initialConfig?.onDemandOnly} bind:value={resolvedConfig} + exportValueFunction /> {/if} diff --git a/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte b/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte index 88b0f11102..fa5ffac8b8 100644 --- a/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte +++ b/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte @@ -124,6 +124,7 @@ refreshIfAutoRefresh('static changed') } + // $: console.log(runnableInputValues) $: (runnableInputValues || extraQueryParams || args) && resultJobLoader && refreshIfAutoRefresh('arg changed')