Skip to content

Commit 4903952

Browse files
committed
Improve validation for new users
1 parent 0034bb0 commit 4903952

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export class BracketsViewer {
5757
*/
5858
// eslint-disable-next-line @typescript-eslint/require-await -- Keep this async for backwards compatibility.
5959
public async render(data: ViewerData, config?: Partial<Config>): Promise<void> {
60+
if (typeof data === 'string')
61+
throw Error('Using a CSS selector as the first argument is deprecated. Please look here: https://github.com/Drarig29/brackets-viewer.js');
62+
6063
const root = document.createDocumentFragment();
6164

6265
this.config = {
@@ -72,6 +75,15 @@ export class BracketsViewer {
7275
if (config?.onMatchClick)
7376
this._onMatchClick = config.onMatchClick;
7477

78+
if (!data.stages?.length)
79+
throw Error('The `data.stages` array is either empty or undefined');
80+
81+
if (!data.participants?.length)
82+
throw Error('The `data.participants` array is either empty or undefined');
83+
84+
if (!data.matches?.length)
85+
throw Error('The `data.matches` array is either empty or undefined');
86+
7587
this.participants = data.participants;
7688
data.participants.forEach(participant => this.participantRefs[participant.id] = []);
7789

@@ -135,6 +147,9 @@ export class BracketsViewer {
135147
*/
136148
private renderStage(root: DocumentFragment, data: ViewerData): void {
137149
const stage = data.stages[0];
150+
if (!data.matches?.length)
151+
throw Error(`No matches found for stage ${stage.id}`);
152+
138153
const matchesByGroup = splitBy(data.matches, 'group_id');
139154

140155
this.stage = stage;

0 commit comments

Comments
 (0)