@@ -11,34 +11,34 @@ import * as AsyncLock from 'async-lock'
1111
1212const LOCK_KEY = 'ChildNodeLoader'
1313
14- export interface ChildNodePage {
15- newChildren : AWSTreeNodeBase [ ]
14+ export interface ChildNodePage < T extends AWSTreeNodeBase = AWSTreeNodeBase > {
15+ newChildren : T [ ]
1616 newContinuationToken : string | undefined
1717}
1818
1919/**
2020 * Controls loading paginated children for LoadMore nodes.
2121 */
22- export class ChildNodeLoader {
23- private readonly loadPage : ( continuationToken : string | undefined ) => Promise < ChildNodePage >
22+ export class ChildNodeLoader < T extends AWSTreeNodeBase = AWSTreeNodeBase > {
23+ private readonly loadPage : ( continuationToken : string | undefined ) => Promise < ChildNodePage < T > >
2424 private readonly moreResults : MoreResultsNode
2525 private readonly loadChildrenLock : AsyncLock
26- private cache : ChildNodeCache
26+ private cache : ChildNodeCache < T >
2727
2828 public constructor (
2929 parent : LoadMoreNode ,
30- loadPage : ( continuationToken : string | undefined ) => Promise < ChildNodePage >
30+ loadPage : ( continuationToken : string | undefined ) => Promise < ChildNodePage < T > >
3131 ) {
3232 this . loadPage = loadPage
3333 this . moreResults = new MoreResultsNode ( parent )
3434 this . loadChildrenLock = new AsyncLock ( )
35- this . cache = new ChildNodeCache ( )
35+ this . cache = new ChildNodeCache < T > ( )
3636 }
3737
3838 /**
3939 * Gets the initial or previously-loaded children.
4040 */
41- public async getChildren ( ) : Promise < AWSTreeNodeBase [ ] > {
41+ public async getChildren ( ) : Promise < ( T | MoreResultsNode ) [ ] > {
4242 await this . loadMoreChildrenIf ( ( ) => ! this . initialChildrenLoaded ( ) )
4343 return this . getExistingChildren ( )
4444 }
@@ -74,7 +74,7 @@ export class ChildNodeLoader {
7474 return this . initialChildrenLoaded ( ) && this . cache . continuationToken === undefined
7575 }
7676
77- private getExistingChildren ( ) : AWSTreeNodeBase [ ] {
77+ private getExistingChildren ( ) : ( T | MoreResultsNode ) [ ] {
7878 if ( this . cache . continuationToken !== undefined ) {
7979 return [ ...this . cache . children , this . moreResults ]
8080 }
0 commit comments