Skip to content

Commit

Permalink
Rename count to length
Browse files Browse the repository at this point in the history
  • Loading branch information
pirelenito committed Jul 25, 2024
1 parent 69c2972 commit f99036b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions packages/@react-facet/core/src/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { EqualityCheck, Facet, NO_VALUE } from '../types'

export type MapProps<T> = {
array: Facet<T[]>
children: (item: Facet<T>, index: number, count: number) => ReactElement | null
children: (item: Facet<T>, index: number, length: number) => ReactElement | null
equalityCheck?: EqualityCheck<T>
}

export const Map = <T,>({ array, children, equalityCheck }: MapProps<T>) => {
const countValue = useFacetUnwrap(useFacetMap((array) => array.length, [], [array]))
const countNumber = countValue !== NO_VALUE ? countValue : 0
const lengthValue = useFacetUnwrap(useFacetMap((array) => array.length, [], [array]))
const lengthNumber = lengthValue !== NO_VALUE ? lengthValue : 0

return (
<>
Expand All @@ -23,14 +23,14 @@ export const Map = <T,>({ array, children, equalityCheck }: MapProps<T>) => {
key={index}
arrayFacet={array}
index={index}
count={countNumber}
length={lengthNumber}
equalityCheck={equalityCheck}
children={children}
/>
) : (
<MapChild<T> key={index} arrayFacet={array} index={index} count={countNumber} children={children} />
<MapChild<T> key={index} arrayFacet={array} index={index} length={lengthNumber} children={children} />
),
countNumber,
lengthNumber,
)}
</>
)
Expand All @@ -39,12 +39,12 @@ export const Map = <T,>({ array, children, equalityCheck }: MapProps<T>) => {
type MapChildMemoProps<T> = {
arrayFacet: Facet<T[]>
index: number
count: number
children: (item: Facet<T>, index: number, count: number) => ReactElement | null
length: number
children: (item: Facet<T>, index: number, length: number) => ReactElement | null
equalityCheck: EqualityCheck<T>
}

const MapChildMemo = <T,>({ arrayFacet, index, count, children, equalityCheck }: MapChildMemoProps<T>) => {
const MapChildMemo = <T,>({ arrayFacet, index, length, children, equalityCheck }: MapChildMemoProps<T>) => {
const childFacet = useFacetMemo(
(array) => {
if (index < array.length) return array[index]
Expand All @@ -54,17 +54,17 @@ const MapChildMemo = <T,>({ arrayFacet, index, count, children, equalityCheck }:
[arrayFacet],
equalityCheck,
)
return children(childFacet, index, count)
return children(childFacet, index, length)
}

type MapChildProps<T> = {
arrayFacet: Facet<T[]>
index: number
count: number
children: (item: Facet<T>, index: number, count: number) => ReactElement | null
length: number
children: (item: Facet<T>, index: number, length: number) => ReactElement | null
}

const MapChild = <T,>({ arrayFacet, index, count, children }: MapChildProps<T>) => {
const MapChild = <T,>({ arrayFacet, index, length, children }: MapChildProps<T>) => {
const childFacet = useFacetMap(
(array) => {
if (index < array.length) return array[index]
Expand All @@ -74,7 +74,7 @@ const MapChild = <T,>({ arrayFacet, index, count, children }: MapChildProps<T>)
[arrayFacet],
)

return children(childFacet, index, count)
return children(childFacet, index, length)
}

interface TimesFn<T> {
Expand Down

0 comments on commit f99036b

Please sign in to comment.