@@ -54,6 +54,8 @@ type SingleCollectionProps<T> = {
5454 collection : Collection < T > ;
5555} ;
5656
57+ type AccessorMap < T > = { [ K in keyof T ] : Accessor < T [ K ] > } ;
58+
5759type DeferredChildren < T extends QueryMapping > = {
5860 alwaysShowContent ?: false ;
5961 children : ( data : Accessor < { [ K in keyof T ] : T [ K ] } > ) => JSXElement ;
@@ -67,18 +69,39 @@ type EagerChildren<T extends QueryMapping> = {
6769 ) => JSXElement ;
6870} ;
6971
72+ type MultiDeferredChildren < T extends QueryMapping > = {
73+ alwaysShowContent ?: false ;
74+ children : ( data : AccessorMap < { [ K in keyof T ] : T [ K ] } > ) => JSXElement ;
75+ } ;
76+
77+ type MultiEagerChildren < T extends QueryMapping > = {
78+ alwaysShowContent : true ;
79+ showLoader ?: true ;
80+ children : (
81+ data : AccessorMap < { [ K in keyof T ] : T [ K ] | undefined } > ,
82+ ) => JSXElement ;
83+ } ;
84+
85+ type SingleSource < T > = SingleQueryProps < T > | SingleCollectionProps < T > ;
86+ type MultiSource < T extends QueryMapping > = QueryProps < T > | CollectionProps < T > ;
87+ type SingleChildren < T > = DeferredChildren < T > | EagerChildren < T > ;
88+ type MultiChildren < T extends QueryMapping > =
89+ | MultiDeferredChildren < T >
90+ | MultiEagerChildren < T > ;
91+
7092export type Props < T extends QueryMapping > = BaseProps &
71- (
72- | QueryProps < T >
73- | SingleQueryProps < T >
74- | CollectionProps < T >
75- | SingleCollectionProps < T >
76- ) &
77- ( DeferredChildren < T > | EagerChildren < T > ) ;
78-
79- export default function AsyncContent < T extends QueryMapping > (
80- props : Props < T > ,
81- ) : JSXElement {
93+ ( SingleSource < T > | MultiSource < T > ) &
94+ ( SingleChildren < T > | MultiChildren < T > ) ;
95+
96+ // Single query/collection overloads
97+ function AsyncContent < T > (
98+ props : BaseProps & SingleSource < T > & SingleChildren < T > ,
99+ ) : JSXElement ;
100+ // Multi query/collection overloads
101+ function AsyncContent < T extends Record < string , unknown > > (
102+ props : BaseProps & MultiSource < T > & MultiChildren < T > ,
103+ ) : JSXElement ;
104+ function AsyncContent < T extends QueryMapping > ( props : Props < T > ) : JSXElement {
82105 //@ts -expect-error this is fine
83106 const source = createMemo < AsyncMap < T > > ( ( ) => {
84107 if ( "query" in props ) {
@@ -150,6 +173,27 @@ export default function AsyncContent<T extends QueryMapping>(
150173 false ,
151174 ) ;
152175
176+ // Keys are stable for the component lifetime; per-key closures track
177+ // reactivity internally via value()/lastResolvedValue().
178+ // oxlint-disable solid/reactivity
179+ const multi = ! ( "defaultQuery" in source ( ) ) ;
180+
181+ const eagerAccessorMap = multi
182+ ? ( Object . fromEntries (
183+ typedKeys ( source ( ) ) . map ( ( key ) => [ key , ( ) => value ( ) ?. [ key ] ] ) ,
184+ ) as AccessorMap < { [ K in keyof T ] : T [ K ] | undefined } > )
185+ : undefined ;
186+
187+ const deferredAccessorMap = multi
188+ ? ( Object . fromEntries (
189+ typedKeys ( source ( ) ) . map ( ( key ) => [
190+ key ,
191+ ( ) => lastResolvedValue ( ) ?. [ key ] ,
192+ ] ) ,
193+ ) as AccessorMap < { [ K in keyof T ] : T [ K ] } > )
194+ : undefined ;
195+ // oxlint-enable solid/reactivity
196+
153197 const loader = ( ) : JSXElement =>
154198 props . loader ?? < LoadingCircle class = "p-4 text-center text-2xl" /> ;
155199
@@ -175,14 +219,18 @@ export default function AsyncContent<T extends QueryMapping>(
175219 fallback = {
176220 < Show when = { hasResolved ( ) } >
177221 { ( _ ) =>
178- props . children (
179- lastResolvedValue as Accessor < { [ K in keyof T ] : T [ K ] } > ,
222+ // oxlint-disable-next-line typescript/no-explicit-any
223+ ( props . children as ( data : any ) => JSXElement ) (
224+ multi ? deferredAccessorMap : lastResolvedValue ,
180225 )
181226 }
182227 </ Show >
183228 }
184229 >
185- { props . children ( value ) }
230+ { /* oxlint-disable-next-line typescript/no-explicit-any */ }
231+ { ( props . children as ( data : any ) => JSXElement ) (
232+ multi ? eagerAccessorMap : value ,
233+ ) }
186234 </ Show >
187235 </ >
188236 }
@@ -225,3 +273,5 @@ function fromCollections<T extends Record<string, unknown>>(collections: {
225273 return acc ;
226274 } , { } as AsyncMap < T > ) ;
227275}
276+
277+ export default AsyncContent ;
0 commit comments