File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -12,12 +12,14 @@ export default class Tab extends YTNode {
12
12
selected : boolean ;
13
13
endpoint : NavigationEndpoint ;
14
14
content : SectionList | MusicQueue | RichGrid | null ;
15
+ contents : ( SectionList | MusicQueue | RichGrid ) [ ] | null ;
15
16
16
17
constructor ( data : RawNode ) {
17
18
super ( ) ;
18
19
this . title = data . title || 'N/A' ;
19
20
this . selected = ! ! data . selected ;
20
21
this . endpoint = new NavigationEndpoint ( data . endpoint ) ;
21
22
this . content = Parser . parseItem ( data . content , [ SectionList , MusicQueue , RichGrid ] ) ;
23
+ this . contents = Parser . parseItems ( data . content , [ SectionList , MusicQueue , RichGrid ] ) ;
22
24
}
23
25
}
Original file line number Diff line number Diff line change @@ -521,6 +521,29 @@ export function parseResponse<T extends IParsedResponse = IParsedResponse>(data:
521
521
return parsed_data ;
522
522
}
523
523
524
+ /**
525
+ * Parses multiple items
526
+ * @param data - The data to parse.
527
+ * @param validTypes - YTNode types that are allowed to be parsed.
528
+ */
529
+ export function parseItems < T extends YTNode , K extends YTNodeConstructor < T > [ ] > ( data : RawNode | undefined , validTypes : K ) : InstanceType < K [ number ] > [ ] | null ;
530
+ export function parseItems < T extends YTNode > ( data : RawNode | undefined , validTypes : YTNodeConstructor < T > ) : T [ ] | null ;
531
+ export function parseItems ( data ?: RawNode ) : YTNode [ ] ;
532
+ export function parseItems ( data ?: RawNode , validTypes ?: YTNodeConstructor | YTNodeConstructor [ ] ) {
533
+ if ( ! data ) return null ;
534
+ const keys = Object . keys ( data ) ;
535
+ const results : YTNode [ ] = [ ] ;
536
+ for ( const key of keys ) {
537
+ const temp_data = { [ key ] : data [ key ] } ;
538
+
539
+ const result = parseItem ( temp_data , validTypes as YTNodeConstructor ) ;
540
+ if ( result ) {
541
+ results . push ( result ) ;
542
+ }
543
+ }
544
+ return results ;
545
+ }
546
+
524
547
/**
525
548
* Parses an item.
526
549
* @param data - The data to parse.
You can’t perform that action at this time.
0 commit comments