Fix dependency ordering

This commit is contained in:
Andrew Kingston 2023-04-14 15:35:47 +01:00
parent b1d227b65f
commit c2de10c076
2 changed files with 46 additions and 38 deletions

View File

@ -39,5 +39,10 @@ export const attachStores = context => {
context = { ...context, ...store.deriveStores?.(context) } context = { ...context, ...store.deriveStores?.(context) }
} }
// Initialise any store logic
for (let store of DependencyOrderedStores) {
store.initialise?.(context)
}
return context return context
} }

View File

@ -20,20 +20,8 @@ export const createStores = () => {
} }
export const deriveStores = context => { export const deriveStores = context => {
const { const { rows, visibleColumns, stickyColumn, rowHeight, width, height } =
scroll, context
rows,
visibleColumns,
stickyColumn,
bounds,
rowHeight,
focusedRow,
focusedCellId,
scrollTop,
scrollLeft,
width,
height,
} = context
// Memoize store primitives // Memoize store primitives
const stickyColumnWidth = derived(stickyColumn, $col => $col?.width || 0, 0) const stickyColumnWidth = derived(stickyColumn, $col => $col?.width || 0, 0)
@ -75,6 +63,45 @@ export const deriveStores = context => {
0 0
) )
// Derive whether to show scrollbars or not
const showVScrollbar = derived(
[contentHeight, height],
([$contentHeight, $height]) => {
return $contentHeight > $height
}
)
const showHScrollbar = derived(
[contentWidth, screenWidth],
([$contentWidth, $screenWidth]) => {
return $contentWidth > $screenWidth
}
)
return {
contentHeight,
contentWidth,
screenWidth,
maxScrollTop,
maxScrollLeft,
showHScrollbar,
showVScrollbar,
}
}
export const initialise = context => {
const {
focusedCellId,
focusedRow,
scroll,
bounds,
rowHeight,
visibleColumns,
scrollTop,
maxScrollTop,
scrollLeft,
maxScrollLeft,
} = context
// Ensure scroll state never goes invalid, which can happen when changing // Ensure scroll state never goes invalid, which can happen when changing
// rows or tables // rows or tables
const overscrollTop = derived( const overscrollTop = derived(
@ -171,28 +198,4 @@ export const deriveStores = context => {
} }
} }
}) })
// Derive whether to show scrollbars or not
const showVScrollbar = derived(
[contentHeight, height],
([$contentHeight, $height]) => {
return $contentHeight > $height
}
)
const showHScrollbar = derived(
[contentWidth, screenWidth],
([$contentWidth, $screenWidth]) => {
return $contentWidth > $screenWidth
}
)
return {
contentHeight,
contentWidth,
screenWidth,
maxScrollTop,
maxScrollLeft,
showHScrollbar,
showVScrollbar,
}
} }