From dbdfd626386398180ecba7976714f86365eeccd8 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 15 Mar 2023 17:22:46 +0100 Subject: [PATCH] fix(frontend): remove staticOutputs from apps --- backend/windmill-worker/src/worker.rs | 3 +- .../apps/components/buttons/AppButton.svelte | 11 ++- .../components/buttons/AppFormButton.svelte | 2 +- .../components/display/AppBarChart.svelte | 9 ++- .../display/AppDisplayComponent.svelte | 8 ++- .../apps/components/display/AppHtml.svelte | 9 ++- .../apps/components/display/AppIcon.svelte | 1 - .../apps/components/display/AppImage.svelte | 1 - .../apps/components/display/AppMap.svelte | 16 ++--- .../apps/components/display/AppPdf.svelte | 11 ++- .../components/display/AppPieChart.svelte | 9 ++- .../components/display/AppScatterChart.svelte | 9 ++- .../apps/components/display/AppText.svelte | 8 ++- .../components/display/AppTimeseries.svelte | 9 ++- .../apps/components/display/PlotlyHtml.svelte | 13 +++- .../components/display/VegaLiteHtml.svelte | 13 +++- .../display/table/AppAggridTable.svelte | 20 +++--- .../components/display/table/AppTable.svelte | 34 ++++------ .../components/helpers/HiddenComponent.svelte | 11 ++- .../helpers/NonRunnableComponent.svelte | 4 +- .../helpers/RunnableComponent.svelte | 2 +- .../apps/components/inputs/AppCheckbox.svelte | 9 ++- .../components/inputs/AppDateInput.svelte | 8 +-- .../components/inputs/AppFileInput.svelte | 8 +-- .../components/inputs/AppMultiSelect.svelte | 8 +-- .../components/inputs/AppNumberInput.svelte | 8 +-- .../components/inputs/AppRangeInput.svelte | 10 +-- .../apps/components/inputs/AppSelect.svelte | 8 +-- .../components/inputs/AppSliderInputs.svelte | 8 +-- .../components/inputs/AppTextInput.svelte | 10 +-- .../inputs/currency/AppCurrencyInput.svelte | 6 +- .../components/layout/AppContainer.svelte | 1 - .../apps/components/layout/AppTabs.svelte | 9 +-- .../components/apps/editor/AppEditor.svelte | 19 ++---- .../components/apps/editor/AppPreview.svelte | 5 +- .../components/apps/editor/GridEditor.svelte | 7 -- .../lib/components/apps/editor/appUtils.ts | 15 ++-- .../apps/editor/component/Component.svelte | 35 +--------- .../component/ComponentNavigation.svelte | 3 +- .../componentsPanel/ComponentList.svelte | 4 +- .../contextPanel/ComponentOutput.svelte | 57 ++++++++-------- .../contextPanel/ComponentOutputViewer.svelte | 16 ++--- .../editor/contextPanel/ContextPanel.svelte | 68 +++++++++---------- .../components/BackgroundScriptOutput.svelte | 11 ++- .../components/TableActionOutput.svelte | 3 +- .../EmptyInlineScript.svelte | 2 +- .../InlineScriptEditor.svelte | 4 +- .../InlineScriptsPanel.svelte | 5 +- .../settingsPanel/ComponentPanel.svelte | 4 -- .../apps/editor/settingsPanel/GridPane.svelte | 5 +- .../apps/editor/settingsPanel/GridTab.svelte | 5 +- .../editor/settingsPanel/TableActions.svelte | 4 +- frontend/src/lib/components/apps/rx.ts | 29 +++----- frontend/src/lib/components/apps/types.ts | 3 +- 54 files changed, 286 insertions(+), 314 deletions(-) diff --git a/backend/windmill-worker/src/worker.rs b/backend/windmill-worker/src/worker.rs index d8b8228e43..4eac1d5b86 100644 --- a/backend/windmill-worker/src/worker.rs +++ b/backend/windmill-worker/src/worker.rs @@ -236,8 +236,7 @@ pub async fn create_token_for_owner<'c>( ) -> error::Result<(Transaction<'c, Postgres>, String)> { // TODO: Bad implementation. We should not have access to this DB here. let token: String = rd_string(30); - let is_super_admin = owner.contains('@') - && sqlx::query_scalar!("SELECT super_admin FROM password WHERE email = $1", owner) + let is_super_admin = sqlx::query_scalar!("SELECT super_admin FROM password WHERE email = $1", email) .fetch_optional(&mut tx) .await? .unwrap_or(false); diff --git a/frontend/src/lib/components/apps/components/buttons/AppButton.svelte b/frontend/src/lib/components/apps/components/buttons/AppButton.svelte index 99cb7e4ea6..45be355c09 100644 --- a/frontend/src/lib/components/apps/components/buttons/AppButton.svelte +++ b/frontend/src/lib/components/apps/components/buttons/AppButton.svelte @@ -11,6 +11,7 @@ import { loadIcon } from '../icon' import { twMerge } from 'tailwind-merge' import { goto } from '$app/navigation' + import { initOutput } from '../../editor/appUtils' export let id: string export let componentInput: AppInput | undefined @@ -25,8 +26,6 @@ export let render: boolean export let initializing: boolean | undefined = true - export const staticOutputs: string[] = ['loading', 'result'] - const { worldStore, app } = getContext('AppViewerContext') let labelValue: string @@ -63,10 +62,10 @@ } } - $: outputs = $worldStore?.outputsById[id] as { - result: Output> - loading: Output - } + let outputs = initOutput($worldStore, id, { + result: undefined, + loading: false + }) $: triggerOnAppLoad && runnableComponent?.runComponent() diff --git a/frontend/src/lib/components/apps/components/buttons/AppFormButton.svelte b/frontend/src/lib/components/apps/components/buttons/AppFormButton.svelte index 6dd580ab76..afcffbb774 100644 --- a/frontend/src/lib/components/apps/components/buttons/AppFormButton.svelte +++ b/frontend/src/lib/components/apps/components/buttons/AppFormButton.svelte @@ -26,7 +26,7 @@ export const staticOutputs: string[] = ['loading', 'result'] - const { app, runnableComponents, worldStore } = getContext('AppViewerContext') + const { app, worldStore } = getContext('AppViewerContext') let labelValue: string = 'Default label' let color: ButtonType.Color diff --git a/frontend/src/lib/components/apps/components/display/AppBarChart.svelte b/frontend/src/lib/components/apps/components/display/AppBarChart.svelte index 7cccf90641..b89e61ca5f 100644 --- a/frontend/src/lib/components/apps/components/display/AppBarChart.svelte +++ b/frontend/src/lib/components/apps/components/display/AppBarChart.svelte @@ -18,6 +18,7 @@ import { concatCustomCss } from '../../utils' import { getContext } from 'svelte' import type { AppViewerContext, ComponentCustomCSS } from '../../types' + import { initOutput } from '../../editor/appUtils' export let id: string export let componentInput: AppInput | undefined @@ -26,8 +27,12 @@ export let customCss: ComponentCustomCSS<'container'> | undefined = undefined export let render: boolean - export const staticOutputs: string[] = ['loading', 'result'] - const { app } = getContext('AppViewerContext') + const { app, worldStore } = getContext('AppViewerContext') + + initOutput($worldStore, id, { + result: undefined, + loading: false + }) ChartJS.register( Title, diff --git a/frontend/src/lib/components/apps/components/display/AppDisplayComponent.svelte b/frontend/src/lib/components/apps/components/display/AppDisplayComponent.svelte index eb970d233c..fcd97ebb90 100644 --- a/frontend/src/lib/components/apps/components/display/AppDisplayComponent.svelte +++ b/frontend/src/lib/components/apps/components/display/AppDisplayComponent.svelte @@ -2,6 +2,7 @@ import DisplayResult from '$lib/components/DisplayResult.svelte' import { getContext } from 'svelte' import { twMerge } from 'tailwind-merge' + import { initOutput } from '../../editor/appUtils' import type { AppInput } from '../../inputType' import { IS_APP_PUBLIC_CONTEXT_KEY, @@ -17,10 +18,13 @@ export let render: boolean const requireHtmlApproval = getContext(IS_APP_PUBLIC_CONTEXT_KEY) - const { app } = getContext('AppViewerContext') + const { app, worldStore } = getContext('AppViewerContext') let result: any = undefined - export const staticOutputs: string[] = ['result', 'loading'] + initOutput($worldStore, id, { + result: undefined, + loading: false + }) diff --git a/frontend/src/lib/components/apps/components/display/AppHtml.svelte b/frontend/src/lib/components/apps/components/display/AppHtml.svelte index a8e5c45eb0..4408a42f2a 100644 --- a/frontend/src/lib/components/apps/components/display/AppHtml.svelte +++ b/frontend/src/lib/components/apps/components/display/AppHtml.svelte @@ -1,5 +1,6 @@ diff --git a/frontend/src/lib/components/apps/components/display/VegaLiteHtml.svelte b/frontend/src/lib/components/apps/components/display/VegaLiteHtml.svelte index c99cf7f474..5e0f3ee93f 100644 --- a/frontend/src/lib/components/apps/components/display/VegaLiteHtml.svelte +++ b/frontend/src/lib/components/apps/components/display/VegaLiteHtml.svelte @@ -1,6 +1,8 @@ ('AppViewerContext') - $: outputs = $worldStore?.outputsById[id] as { + $: outputs = $worldStore?.outputsById?.[id] as { loading: Output result: Output } @@ -25,7 +25,7 @@ } function setOutput(v: any) { - outputs.result?.set(v, true) + outputs?.result?.set(v, true) } $: result && outputs && setOutput(result) diff --git a/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte b/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte index 57ba23a3c3..19b7b5aa56 100644 --- a/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte +++ b/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte @@ -113,7 +113,7 @@ let testJob: CompletedJob | undefined = undefined let testJobLoader: TestJobLoader | undefined = undefined - $: outputs = initOutput($worldStore, id, { result: undefined, loading: false }) + let outputs = initOutput($worldStore, id, { result: undefined, loading: false }) $: outputs?.loading?.set(testIsLoading) $: schemaStripped = stripSchema(fields, $stateId) diff --git a/frontend/src/lib/components/apps/components/inputs/AppCheckbox.svelte b/frontend/src/lib/components/apps/components/inputs/AppCheckbox.svelte index c6e6f52134..b915ccb21f 100644 --- a/frontend/src/lib/components/apps/components/inputs/AppCheckbox.svelte +++ b/frontend/src/lib/components/apps/components/inputs/AppCheckbox.svelte @@ -1,6 +1,7 @@ diff --git a/frontend/src/lib/components/apps/editor/GridEditor.svelte b/frontend/src/lib/components/apps/editor/GridEditor.svelte index dd135aab89..e05353c754 100644 --- a/frontend/src/lib/components/apps/editor/GridEditor.svelte +++ b/frontend/src/lib/components/apps/editor/GridEditor.svelte @@ -13,7 +13,6 @@ import { push } from '$lib/history' import { expandGriditem, findGridItem, sortGridItemsPosition } from './appUtils' import Grid from '../svelte-grid/Grid.svelte' - import { settableOutput } from '../rx' export let policy: Policy @@ -22,7 +21,6 @@ app, mode, connectingInput, - staticOutputs, runnableComponents, summary, focusedGrid, @@ -84,10 +82,6 @@ return gridComponent.data.id !== component?.id }) - // Delete static inputs - delete $staticOutputs[component.id] - $staticOutputs = $staticOutputs - delete $runnableComponents[component.id] $runnableComponents = $runnableComponents @@ -240,7 +234,6 @@ name={script.name} fields={script.fields} autoRefresh={script.autoRefresh ?? false} - bind:staticOutputs={$staticOutputs[`bg_${index}`]} /> {/if} {/each} diff --git a/frontend/src/lib/components/apps/editor/appUtils.ts b/frontend/src/lib/components/apps/editor/appUtils.ts index c686966e92..0034a92b0c 100644 --- a/frontend/src/lib/components/apps/editor/appUtils.ts +++ b/frontend/src/lib/components/apps/editor/appUtils.ts @@ -306,15 +306,9 @@ export function initOutput>( if (!world) { return {} as any } - const output = world.outputsById[id] as Outputtable - if (init) { - for (const key in init) { - if (output && output[key] && output[key].peak() == undefined) { - output[key].set(init[key] as any) - } - } - } - return output + return Object.fromEntries( + Object.entries(init).map(([key, value]) => [key, world.newOutput(id, key, value)]) + ) as Outputtable } export function expandGriditem( grid: GridItem[], @@ -391,6 +385,9 @@ export function recursivelyFilterKeyInJSON( search: string, extraSearch?: string | undefined ): object { + if (!search || search == '') { + return json + } let filteredJSON = {} Object.keys(json).forEach((key) => { if ( diff --git a/frontend/src/lib/components/apps/editor/component/Component.svelte b/frontend/src/lib/components/apps/editor/component/Component.svelte index fd64f88745..e30e7a14a5 100644 --- a/frontend/src/lib/components/apps/editor/component/Component.svelte +++ b/frontend/src/lib/components/apps/editor/component/Component.svelte @@ -1,6 +1,5 @@ -{#if $staticOutputs[gridItem.id] || gridItem.data.numberOfSubgrids > 1} - { - if (!$connectingInput.opened) { - onHeaderClick(e.detail.manuallyOpen) - } - }} - id={gridItem.id} - name={getComponentNameById(gridItem.id)} - {first} - {nested} - {expanded} - > -
- { - if ($connectingInput.opened) { - $connectingInput = connectInput($connectingInput, gridItem.id, detail) - } - }} - /> -
+ { + if (!$connectingInput.opened) { + onHeaderClick(e.detail.manuallyOpen) + } + }} + id={gridItem.id} + name={getComponentNameById(gridItem.id)} + {first} + {nested} + {expanded} +> +
+ { + if ($connectingInput.opened) { + $connectingInput = connectInput($connectingInput, gridItem.id, detail) + } + }} + /> +
- - -
-{/if} + + +
diff --git a/frontend/src/lib/components/apps/editor/contextPanel/ComponentOutputViewer.svelte b/frontend/src/lib/components/apps/editor/contextPanel/ComponentOutputViewer.svelte index c199420a43..1424b21bd9 100644 --- a/frontend/src/lib/components/apps/editor/contextPanel/ComponentOutputViewer.svelte +++ b/frontend/src/lib/components/apps/editor/contextPanel/ComponentOutputViewer.svelte @@ -6,7 +6,6 @@ import type { AppViewerContext } from '../../types' import { recursivelyFilterKeyInJSON } from '../appUtils' - export let outputs: string[] = [] export let componentId: string const { worldStore } = getContext('AppViewerContext') @@ -14,22 +13,21 @@ let object = {} - function subscribeToAllOutputs(observableOutputs: Record>) { + function subscribeToAllOutputs(observableOutputs: Record> | undefined) { if (observableOutputs) { - outputs?.forEach((output: string) => { - object[output] = undefined - observableOutputs[output]?.subscribe({ - id: 'alloutputs' + output, + Object.entries(observableOutputs).forEach(([k, output]) => { + object[k] = undefined + output?.subscribe({ + id: 'alloutputs' + componentId + '-' + k, next: (value) => { - object[output] = value + object[k] = value } }) }) } } - $: $worldStore?.outputsById[componentId] && - subscribeToAllOutputs($worldStore.outputsById[componentId]) + $: subscribeToAllOutputs($worldStore?.outputsById?.[componentId]) $: filtered = recursivelyFilterKeyInJSON(object, $search, componentId) diff --git a/frontend/src/lib/components/apps/editor/contextPanel/ContextPanel.svelte b/frontend/src/lib/components/apps/editor/contextPanel/ContextPanel.svelte index 2f4eec5f5b..f359becc39 100644 --- a/frontend/src/lib/components/apps/editor/contextPanel/ContextPanel.svelte +++ b/frontend/src/lib/components/apps/editor/contextPanel/ContextPanel.svelte @@ -13,7 +13,7 @@ import MinMaxButton from './components/MinMaxButton.svelte' import OutputHeader from './components/OutputHeader.svelte' - const { connectingInput, app, state } = getContext('AppViewerContext') + const { connectingInput, app, worldStore } = getContext('AppViewerContext') let search = writable('') let expanded = false @@ -54,42 +54,42 @@
-
- State & Context + {#key $worldStore?.outputsById} +
+ State & Context - - { - $connectingInput = connectInput($connectingInput, 'ctx', detail) - }} - /> - + + { + $connectingInput = connectInput($connectingInput, 'ctx', detail) + }} + /> + - - { - $connectingInput = connectInput($connectingInput, 'state', detail) - }} - /> - -
- -
- Components - {#each $app.grid as gridItem, index (gridItem.id)} - - {/each} -
-
- Background scripts -
- + + { + $connectingInput = connectInput($connectingInput, 'state', detail) + }} + /> +
-
+ +
+ Components + {#each $app.grid as gridItem, index (gridItem.id)} + + {/each} +
+
+ Background scripts +
+ +
+
+ {/key}
diff --git a/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptOutput.svelte b/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptOutput.svelte index b821334163..80d63a3a3c 100644 --- a/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptOutput.svelte +++ b/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptOutput.svelte @@ -14,7 +14,11 @@ function onHeaderClick(manuallyOpen: boolean) { if (manuallyOpen) { - $selectedComponent = undefined + if (id) { + $selectedComponent = id + } else { + $selectedComponent = undefined + } } else { $selectedComponent = id } @@ -28,13 +32,14 @@ {first} {expanded} on:handleClick={(e) => { - onHeaderClick(e.detail.manuallyOpen) + if (!$connectingInput.opened) { + onHeaderClick(e.detail.manuallyOpen) + } }} shouldOpen={$selectedComponent === id} > { $connectingInput = connectInput($connectingInput, id, detail) }} diff --git a/frontend/src/lib/components/apps/editor/contextPanel/components/TableActionOutput.svelte b/frontend/src/lib/components/apps/editor/contextPanel/components/TableActionOutput.svelte index 7537e070c7..f9f0b4dfdb 100644 --- a/frontend/src/lib/components/apps/editor/contextPanel/components/TableActionOutput.svelte +++ b/frontend/src/lib/components/apps/editor/contextPanel/components/TableActionOutput.svelte @@ -5,7 +5,7 @@ import ComponentOutputViewer from '../ComponentOutputViewer.svelte' import OutputHeader from './OutputHeader.svelte' - const { staticOutputs, connectingInput } = getContext('AppViewerContext') + const { connectingInput } = getContext('AppViewerContext') export let id: string export let expanded: boolean = false @@ -15,7 +15,6 @@ { $connectingInput = connectInput($connectingInput, id, detail) }} diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/EmptyInlineScript.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/EmptyInlineScript.svelte index 05fa2284fa..c18883a745 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/EmptyInlineScript.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/EmptyInlineScript.svelte @@ -56,7 +56,7 @@ } async function newInlineScript(content: string, language: Preview.language, path: string) { - const fullPath = `${appPath}/inline-script/${path}` + const fullPath = `${appPath}/${path}` let schema: Schema = emptySchema() diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditor.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditor.svelte index b6a7400828..c6d369504a 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditor.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditor.svelte @@ -27,7 +27,7 @@ export let fields: Record = {} export let syncFields: boolean = false - const { runnableComponents, stateId, worldStore, state } = + const { runnableComponents, stateId, worldStore, state, appPath } = getContext('AppViewerContext') let editor: Editor @@ -49,6 +49,8 @@ return schema } + $: inlineScript.path = `${appPath}/${name}` + onMount(async () => { if (inlineScript && !inlineScript.schema) { if (inlineScript.language != 'frontend') { diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanel.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanel.svelte index 530fffe813..83019b5987 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanel.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanel.svelte @@ -8,8 +8,7 @@ import EmptyInlineScript from './EmptyInlineScript.svelte' import InlineScriptEditorPanel from './InlineScriptEditorPanel.svelte' - const { app, staticOutputs, runnableComponents } = - getContext('AppViewerContext') + const { app, runnableComponents } = getContext('AppViewerContext') let selectedScriptComponentId: string | undefined = undefined @@ -18,9 +17,7 @@ $app.hiddenInlineScripts.splice(index, 1) $app.hiddenInlineScripts = [...$app.hiddenInlineScripts] - delete $staticOutputs[`bg_${index}`] delete $runnableComponents[`bg_${index}`] - $staticOutputs = $staticOutputs } diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte index 9dec3027e9..c94993d849 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte @@ -35,7 +35,6 @@ const { app, - staticOutputs, runnableComponents, selectedComponent, worldStore, @@ -53,15 +52,12 @@ if (component && !noGrid) { let ids = deleteGridItem($app, component, parent, false) for (const key of ids) { - delete $staticOutputs[key] delete $runnableComponents[key] } } - delete $staticOutputs[component.id] delete $runnableComponents[component.id] $app = $app - $staticOutputs = $staticOutputs $runnableComponents = $runnableComponents onDelete?.() diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/GridPane.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/GridPane.svelte index d40828e238..a158f200bb 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/GridPane.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/GridPane.svelte @@ -10,8 +10,7 @@ export let panes: number[] export let component: AppComponent - const { app, staticOutputs, runnableComponents } = - getContext('AppViewerContext') + const { app, runnableComponents } = getContext('AppViewerContext') function addTab() { const numberOfPanes = panes.length @@ -33,11 +32,9 @@ const components = deleteGridItem($app, item.data, subgrid, false) console.log(components) for (const key in components) { - delete $staticOutputs[key] delete $runnableComponents[key] } } - $staticOutputs = $staticOutputs $runnableComponents = $runnableComponents for (let i = index; i < panes.length - 1; i++) { $app!.subgrids![`${component.id}-${i}`] = $app!.subgrids![`${component.id}-${i + 1}`] diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/GridTab.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/GridTab.svelte index 70245a8106..1e2900b70b 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/GridTab.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/GridTab.svelte @@ -12,8 +12,7 @@ export let tabs: string[] export let component: AppComponent - const { app, staticOutputs, runnableComponents, focusedGrid } = - getContext('AppViewerContext') + const { app, runnableComponents } = getContext('AppViewerContext') function addTab() { const numberOfTabs = tabs.length @@ -33,11 +32,9 @@ const components = deleteGridItem($app, item.data, subgrid, false) console.log(components) for (const key in components) { - delete $staticOutputs[key] delete $runnableComponents[key] } } - $staticOutputs = $staticOutputs $runnableComponents = $runnableComponents for (let i = index; i < tabs.length - 1; i++) { $app!.subgrids![`${component.id}-${i}`] = $app!.subgrids![`${component.id}-${i + 1}`] diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/TableActions.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/TableActions.svelte index 36d04bb5d1..4a6885ad4d 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/TableActions.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/TableActions.svelte @@ -14,7 +14,7 @@ export let components: (BaseAppComponent & ButtonComponent)[] export let id: string - const { selectedComponent, staticOutputs } = getContext('AppViewerContext') + const { selectedComponent } = getContext('AppViewerContext') function addComponent() { const actionId = getNextId(components.map((x) => x.id.split('_')[1])) @@ -90,8 +90,6 @@ function deleteComponent(cid: string) { components = components.filter((x) => x.id !== cid) - delete $staticOutputs[cid] - $staticOutputs = $staticOutputs $selectedComponent = id } diff --git a/frontend/src/lib/components/apps/rx.ts b/frontend/src/lib/components/apps/rx.ts index ed417b044b..03360670f9 100644 --- a/frontend/src/lib/components/apps/rx.ts +++ b/frontend/src/lib/components/apps/rx.ts @@ -1,5 +1,5 @@ import type { AppInput } from './inputType' -import { writable, type Writable } from 'svelte/store' +import { get, writable, type Writable } from 'svelte/store' import { deepEqual } from 'fast-equals' export interface Subscriber { @@ -26,36 +26,22 @@ export type World = { newOutput: (id: string, name: string, previousValue: T) => Output } -export function buildWorld( - components: Record, - previousWorld: World | undefined, - context: Record -): World { +export function buildWorld(context: Record): Writable { const newWorld = buildObservableWorld() const stateId = writable(0) - + let writableWorld: Writable | undefined = undefined const outputsById: Record>> = { ctx: Object.fromEntries( Object.entries(context).map(([k, v]) => { return [k, newWorld.newOutput('ctx', k, stateId, v)] }) ), - state: previousWorld?.outputsById?.state ?? {} + state: {} } - for (const [k, outputs] of Object.entries(components)) { - outputsById[k] = {} - for (const o of outputs) { - outputsById[k][o] = newWorld.newOutput( - k, - o, - stateId, - previousWorld?.outputsById[k]?.[o]?.peak() - ) - } - } function newOutput(id: string, name: string, previousValue: T) { if (outputsById[id]?.[name]) { + writableWorld?.update((x) => x) return outputsById[id][name] } let o = newWorld.newOutput(id, name, stateId, previousValue) @@ -63,11 +49,12 @@ export function buildWorld( outputsById[id] = {} } outputsById[id][name] = o + writableWorld?.update((x) => x) return o } stateId.update((x) => x + 1) - - return { outputsById, connect: newWorld.connect, stateId, newOutput } + writableWorld = writable({ outputsById, connect: newWorld.connect, stateId, newOutput }) + return writableWorld } export function buildObservableWorld() { diff --git a/frontend/src/lib/components/apps/types.ts b/frontend/src/lib/components/apps/types.ts index 9c5bec41ea..bc9639c31c 100644 --- a/frontend/src/lib/components/apps/types.ts +++ b/frontend/src/lib/components/apps/types.ts @@ -114,8 +114,7 @@ export type ConnectingInput = { } export type AppViewerContext = { - worldStore: Writable - staticOutputs: Writable> + worldStore: Writable app: Writable summary: Writable selectedComponent: Writable