From 37393c4e2a02a6923b0f66e441adc661635f8cfb Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 3 Mar 2023 09:02:19 +0000 Subject: [PATCH] Refactor stores and make state more modular --- .../src/components/sheet/DeleteButton.svelte | 4 -- .../src/components/sheet/Sheet.svelte | 46 +++++-------------- .../src/components/sheet/SheetBody.svelte | 12 ++++- .../src/components/sheet/StickyColumn.svelte | 14 ++++-- .../src/components/sheet/stores/bounds.js | 11 +++++ .../src/components/sheet/stores/interface.js | 42 +++++++++++++++++ .../src/components/sheet/stores/rows.js | 5 +- .../src/components/sheet/stores/scroll.js | 9 +++- 8 files changed, 92 insertions(+), 51 deletions(-) create mode 100644 packages/frontend-core/src/components/sheet/stores/bounds.js create mode 100644 packages/frontend-core/src/components/sheet/stores/interface.js diff --git a/packages/frontend-core/src/components/sheet/DeleteButton.svelte b/packages/frontend-core/src/components/sheet/DeleteButton.svelte index 3abf7e1530..a7295c88f3 100644 --- a/packages/frontend-core/src/components/sheet/DeleteButton.svelte +++ b/packages/frontend-core/src/components/sheet/DeleteButton.svelte @@ -20,10 +20,6 @@ // Deletion callback when confirmed const performDeletion = async () => { await rows.actions.deleteRows(rowsToDelete) - - // Refresh state - $selectedCellId = null - $selectedRows = {} } diff --git a/packages/frontend-core/src/components/sheet/Sheet.svelte b/packages/frontend-core/src/components/sheet/Sheet.svelte index e747d115c5..5fedba5c1b 100644 --- a/packages/frontend-core/src/components/sheet/Sheet.svelte +++ b/packages/frontend-core/src/components/sheet/Sheet.svelte @@ -6,6 +6,8 @@ import { createRowsStore } from "./stores/rows" import { createColumnsStores } from "./stores/columns" import { createScrollStores } from "./stores/scroll" + import { createBoundsStores } from "./stores/bounds" + import { createInterfaceStores } from "./stores/interface" import DeleteButton from "./DeleteButton.svelte" import SheetBody from "./SheetBody.svelte" import SheetRow from "./SheetRow.svelte" @@ -38,42 +40,23 @@ allowAddColumns, allowSelectRows, }) - const selectedCellId = writable() - const selectedRows = writable({}) - const hoveredRowId = writable() - const scroll = writable({ - left: 0, - top: 0, - }) - const bounds = writable({ - left: 0, - top: 0, - width: 0, - height: 0, - }) - // Build up spreadsheet context and additional stores + // Build up spreadsheet context + // Stores are listed in order of dependency on each other let context = { API: API || createAPIClient(), rand, - selectedCellId, - selectedRows, cellHeight, - bounds, - scroll, - hoveredRowId, config, dispatch, } - const { rows, schema } = createRowsStore(context) - context = { ...context, rows, schema } - const { columns, stickyColumn } = createColumnsStores(context) - context = { ...context, columns, stickyColumn } + context = { ...context, ...createRowsStore(context) } + context = { ...context, ...createColumnsStores(context) } + context = { ...context, ...createBoundsStores(context) } context = { ...context, ...createScrollStores(context) } - const { visibleRows, visibleColumns } = createViewportStores(context) - context = { ...context, visibleRows, visibleColumns } - const { reorder } = createReorderStores(context) - context = { ...context, reorder } + context = { ...context, ...createViewportStores(context) } + context = { ...context, ...createReorderStores(context) } + context = { ...context, ...createInterfaceStores(context) } // Keep config store up to date $: config.set({ @@ -94,14 +77,7 @@
- - {#each $visibleRows as row} - - {/each} - {#if allowAddRows} - - {/if} - +
diff --git a/packages/frontend-core/src/components/sheet/SheetBody.svelte b/packages/frontend-core/src/components/sheet/SheetBody.svelte index 9f2acb0501..b636f4eabe 100644 --- a/packages/frontend-core/src/components/sheet/SheetBody.svelte +++ b/packages/frontend-core/src/components/sheet/SheetBody.svelte @@ -1,8 +1,11 @@