File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export function repeat<T>(
2424 options : { fallback ?: Accessor < T > } = { } ,
2525) : Accessor < T [ ] > {
2626 let prev : readonly T [ ] = [ ] ;
27- let prevLen = 0 ;
27+ let prevLen : number | undefined ;
2828 const disposers : ( ( ) => void ) [ ] = [ ] ;
2929 onCleanup ( ( ) => {
3030 for ( let index = 0 ; index < disposers . length ; index ++ ) {
@@ -75,7 +75,7 @@ export function repeat<T>(
7575 const next = prev . slice ( 0 , len ) ;
7676
7777 // Create new elements as needed
78- for ( let index = prevLen ; index < len ; index ++ ) {
78+ for ( let index = prevLen ?? 0 ; index < len ; index ++ ) {
7979 next [ index ] = createRoot ( dispose => {
8080 disposers [ index ] = dispose ;
8181 return mapFn ( index ) ;
Original file line number Diff line number Diff line change @@ -82,6 +82,17 @@ describe("repeat", () => {
8282 setLength ( 3 ) ;
8383 expect ( mapped ( ) , "mapped after dispose" ) . toEqual ( [ "fb" ] ) ;
8484 } ) ) ;
85+
86+ it ( "uses fallback when length is initially 0" , ( ) =>
87+ createRoot ( disposer => {
88+ const map = repeat (
89+ ( ) => 0 ,
90+ i => i ,
91+ { fallback : ( ) => NaN } ,
92+ ) ;
93+ expect ( map ( ) ) . toEqual ( [ NaN ] ) ;
94+ disposer ( ) ;
95+ } ) ) ;
8596} ) ;
8697
8798describe ( "<Repeat/>" , ( ) => {
You can’t perform that action at this time.
0 commit comments