Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions src/Selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ export function Select({ enabled = false, children, ...props }: SelectApi) {
const group = useRef<THREE.Group>(null!)
const api = useContext(selectionContext)
useEffect(() => {
if (api && enabled) {
let changed = false
const current: THREE.Object3D<THREE.Event>[] = []
group.current.traverse((o) => {
o.type === 'Mesh' && current.push(o)
if (api.selected.indexOf(o) === -1) changed = true
})
if (changed) {
api.select((state) => [...state, ...current])
return () => {
api.select((state) => state.filter((selected) => !current.includes(selected)))
}
}
if (!api) return
const current: THREE.Object3D<THREE.Event>[] = []
group.current.traverse((o) => {
if (o.type === 'Mesh') current.push(o)
})
if (enabled && current.some(o => !api.selected.includes(o))) {
api.select(state => [...state, ...current])
} else if (!enabled && current.some(o => api.selected.includes(o))) {
api.select(state => state.filter(o => !current.includes(o)))
Comment on lines -25 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the cleanup handler? I'm not sure I understand when L33 is supposed to happen in the case of a Select unmounting with any number of siblings rather than parents who rerender when children change (e.g. <Selection> <Select /> <Select /> </Selection>).

}
}, [enabled, children, api])
return (
Expand Down