Skip to content

Commit

Permalink
Don't dereference null pointer if elements don't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
jes committed Apr 28, 2024
1 parent f089bb0 commit e4b0341
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions testbed/StageTestbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,28 @@ Testbed.mount = () => {
const statusElement = document.getElementById('testbed-status');
const infoElement = document.getElementById('testbed-info');

playButton.addEventListener('click', () => {
mounted.isPaused() ? mounted.resume() : mounted.pause();
});
if (playButton) {
playButton.addEventListener('click', () => {
mounted.isPaused() ? mounted.resume() : mounted.pause();
});

mounted._pause = () => {
playButton.classList.add('pause');
playButton.classList.remove('play');
};
mounted._pause = () => {
playButton.classList.add('pause');
playButton.classList.remove('play');
};

mounted._resume = () => {
playButton.classList.add('play');
playButton.classList.remove('pause');
};
mounted._resume = () => {
playButton.classList.add('play');
playButton.classList.remove('pause');
};
} else {
console.log("Please create a button with id='testbed-play'");
}

let lastStatus = '';
statusElement.innerText = lastStatus;
if (statusElement) {
statusElement.innerText = lastStatus;
}
mounted._status = (text: string) => {
if (lastStatus === text) {
return;
Expand All @@ -88,7 +94,9 @@ Testbed.mount = () => {
};

let lastInfo = '';
infoElement.innerText = lastInfo;
if (infoElement) {
infoElement.innerText = lastInfo;
}
mounted._info = (text: string) => {
if (lastInfo === text) {
return;
Expand Down

0 comments on commit e4b0341

Please sign in to comment.