Skip to content

Commit

Permalink
fix(MultiMarkersPlayerBar): avoid observing undefined objects
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Mar 8, 2023
1 parent 0d35fe0 commit f351770
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/parser/classes/DecoratedPlayerBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import Parser from '../index.js';
import { YTNode } from '../helpers.js';
import type Button from './Button.js';
import type MultiMarkersPlayerBar from './MultiMarkersPlayerBar.js';
import type { RawNode } from '../index.js';

class DecoratedPlayerBar extends YTNode {
static type = 'DecoratedPlayerBar';

player_bar: MultiMarkersPlayerBar | null;
player_bar_action_button: Button | null;

constructor(data: any) {
constructor(data: RawNode) {
super();
this.player_bar = Parser.parseItem<MultiMarkersPlayerBar>(data.playerBar);
this.player_bar_action_button = Parser.parseItem<Button>(data.playerBarActionButton);
Expand Down
10 changes: 7 additions & 3 deletions src/parser/classes/MultiMarkersPlayerBar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Parser from '../index.js';
import type Chapter from './Chapter.js';
import type Heatmap from './Heatmap.js';
import type { RawNode } from '../index.js';

import { observe, ObservedArray, YTNode } from '../helpers.js';

Expand All @@ -13,7 +14,7 @@ class Marker extends YTNode {
chapters?: Chapter[];
};

constructor (data: any) {
constructor (data: RawNode) {
super();
this.marker_key = data.key;

Expand All @@ -34,9 +35,12 @@ class MultiMarkersPlayerBar extends YTNode {

markers_map: ObservedArray<Marker>;

constructor(data: any) {
constructor(data: RawNode) {
super();
this.markers_map = observe(data.markersMap?.map((marker: { key: string; value: { [key: string ]: any }}) => new Marker(marker)));
this.markers_map = observe(data.markersMap?.map((marker: {
key: string;
value: { [key: string ]: any
}}) => new Marker(marker)) || []);
}
}

Expand Down

0 comments on commit f351770

Please sign in to comment.