refactor!: migrate core renderers to TypeScript

This commit is contained in:
LuanRT
2022-08-07 06:14:09 -03:00
parent 3833b333a7
commit 709c448053
8 changed files with 66 additions and 13 deletions

View File

@@ -4,9 +4,11 @@ import { YTNode } from '../helpers';
class BrowseFeedActions extends YTNode {
static type = 'BrowseFeedActions';
constructor(data) {
contents;
constructor(data: any) {
super();
this.contents = Parser.parse(data.contents);
this.contents = Parser.parseArray(data.contents);
}
}

View File

@@ -1,12 +1,18 @@
import Parser from '../index';
import ItemSectionHeader from './ItemSectionHeader';
import { YTNode } from '../helpers';
class ItemSection extends YTNode {
static type = 'ItemSection';
constructor(data) {
header: ItemSectionHeader | null;
contents;
target_id;
constructor(data: any) {
super();
this.header = Parser.parse(data.header);
this.header = Parser.parseItem<ItemSectionHeader>(data.header, ItemSectionHeader);
this.contents = Parser.parse(data.contents, true);
if (data.targetId || data.sectionIdentifier) {

View File

@@ -4,7 +4,9 @@ import { YTNode } from '../helpers';
class ItemSectionHeader extends YTNode {
static type = 'ItemSectionHeader';
constructor(data) {
title: Text;
constructor(data: any) {
super();
this.title = new Text(data.title);
}

View File

@@ -1,15 +1,21 @@
import Text from './misc/Text';
import Parser from '../index';
import MusicThumbnail from './MusicThumbnail';
import { YTNode } from '../helpers';
class MusicImmersiveHeader extends YTNode {
static type = 'MusicImmersiveHeader';
constructor(data) {
title: Text;
description: Text;
thumbnail: MusicThumbnail | null;
constructor(data: any) {
super();
this.title = new Text(data.title);
this.description = new Text(data.description);
this.thumbnails = Parser.parse(data.thumbnail);
this.thumbnail = Parser.parseItem<MusicThumbnail>(data.thumbnail, MusicThumbnail);
/**
Not useful for now.
this.menu = Parser.parse(data.menu);

View File

@@ -0,0 +1,28 @@
import Parser from '../index';
import Text from './misc/Text';
import NavigationEndpoint from './NavigationEndpoint';
import MusicResponsiveListItem from './MusicResponsiveListItem';
import { YTNode } from '../helpers';
class MusicShelf extends YTNode {
static type = 'MusicShelf';
title: Text;
contents;
endpoint: NavigationEndpoint | null;
continuation: string | null;
bottom_text: Text | null;
constructor(data: any) {
super();
this.title = new Text(data.title);
this.contents = Parser.parseArray<MusicResponsiveListItem>(data.contents, MusicResponsiveListItem);
this.endpoint = Reflect.has(data, 'bottomEndpoint') ? new NavigationEndpoint(data.bottomEndpoint) : null;
this.continuation = data.continuations?.[0]?.nextContinuationData?.continuation || null;
this.bottom_text = Reflect.has(data, 'bottomText') ? new Text(data.bottomText) : null;
}
}
export default MusicShelf;

View File

@@ -4,9 +4,11 @@ import { YTNode } from '../helpers';
class MusicThumbnail extends YTNode {
static type = 'MusicThumbnail';
constructor(data) {
contents;
constructor(data: any) {
super();
return Thumbnail.fromResponse(data.thumbnail);
this.contents = Thumbnail.fromResponse(data.thumbnail);
}
}

View File

@@ -1,12 +1,16 @@
import Parser from '../index';
import Tab from './Tab';
import { YTNode } from '../helpers';
class SingleColumnBrowseResults extends YTNode {
static type = 'SingleColumnBrowseResults';
constructor(data) {
tabs;
constructor(data: any) {
super();
this.tabs = Parser.parse(data.tabs);
this.tabs = Parser.parseArray<Tab>(data.tabs, Tab);
}
}

View File

@@ -1,12 +1,15 @@
import Parser from '../index';
import { YTNode } from '../helpers';
import Tab from './Tab';
class TabbedSearchResults extends YTNode {
static type = 'TabbedSearchResults';
constructor(data) {
tabs;
constructor(data: any) {
super();
this.tabs = Parser.parse(data.tabs);
this.tabs = Parser.parseArray<Tab>(data.tabs, Tab);
}
}