import { useSelector } from './use-selector' ; import { atom } from '../atom-constructors' ; import { equalNumberArray , getAtomAtIndex } from '../inner-utils' ; import { Atom , RemovableAtom } from '../types' ; export function useAtomSlice < T , S extends T > ( arrayAtom , filterBy ? ) ; export function useAtomSlice < T > ( arrayAtom , filterBy ? ) ; export function useAtomSlice < T > ( arrayAtom , filterBy ? ) { const keptIndexesAtom = atom ( get => { return filterBy ? get ( arrayAtom ) . flatMap ( ( value , index ) => { return filterBy ( value ) ? [ index ] : [ ] ; } ) : get ( arrayAtom ) . map ( ( _ , index ) => index ) ; } ) ; const keptIndexes = useSelector ( keptIndexesAtom , v => v , equalNumberArray ) ; return keptIndexes . map ( index => getAtomAtIndex ( arrayAtom , index ) ) ; }