I have code like this:
function MultiAllotment({...}) {
return <Allotment
ref={allotmentRef}
vertical={split === 'vertical'}
defaultSizes={defaultSizes}
separator={!hideSeparator}
onVisibleChange={(index, visible) => panes[index].onVisibleChange?.(visible)}
onChange={(sizes) => panes.forEach((pane, index) => pane.onChange?.(sizes[index]))}
onDragEnd={(sizes) => panes.forEach((pane, index) => pane.onDragEnd?.(sizes[index]))}
className={styles.main}
>
{panes.map(({ id, visible, snap, preferredSize, minSize, maxSize, className, children }) => (
<Allotment.Pane
key={id}
visible={visible}
snap={snap}
preferredSize={preferredSize}
minSize={minSize}
maxSize={maxSize}
className={className}
>
{children}
</Allotment.Pane>
))}
</Allotment>
}
It's failing here:
|
if (index < 0 || index >= this.viewItems.length) { |
|
throw new Error("Index out of bounds"); |
|
} |
This is because we're calling isViewVisible() for each index in childrenArray:
|
splitViewRef.current?.isViewVisible(index) !== props.visible |
...which means we'll throw an error if our SplitView has fewer viewItems than the childrenArray we passed to the Allotment. Whenever the exception is thrown, the SplitView has an empty viewItems array.
But... I don't know why we should expect SplitView to have the same number of viewItems as childrenArray, or why we shouldn't expect viewItems to be nonempty. Is there any guarantee that these arrays are the same size or that the viewItems will be nonempty? I can't find anything in the documentation that would imply that I'm using Allotment incorrectly.
If there is no guarantee, should we really be throwing an exception? This is a predicate function. Can it return false instead?
I have code like this:
It's failing here:
allotment/src/split-view/split-view.ts
Lines 548 to 550 in 451dfb6
This is because we're calling
isViewVisible()for each index inchildrenArray:allotment/src/allotment.tsx
Line 405 in 451dfb6
...which means we'll throw an error if our
SplitViewhas fewerviewItemsthan thechildrenArraywe passed to theAllotment. Whenever the exception is thrown, theSplitViewhas an emptyviewItemsarray.But... I don't know why we should expect
SplitViewto have the same number ofviewItemsaschildrenArray, or why we shouldn't expectviewItemsto be nonempty. Is there any guarantee that these arrays are the same size or that theviewItemswill be nonempty? I can't find anything in the documentation that would imply that I'm usingAllotmentincorrectly.If there is no guarantee, should we really be throwing an exception? This is a predicate function. Can it return
falseinstead?