demo: Use switch statement instead of branches

This commit is contained in:
Daniel Jacobs 2022-08-03 13:47:55 -04:00 committed by Mike Welsh
parent 7343acf65b
commit a2968e6ecb
1 changed files with 11 additions and 9 deletions

View File

@ -99,19 +99,21 @@ function load(options) {
for (const [key, value] of Object.entries(this.metadata)) { for (const [key, value] of Object.entries(this.metadata)) {
const metadataElement = document.getElementById(key); const metadataElement = document.getElementById(key);
if (metadataElement) { if (metadataElement) {
if (key === "backgroundColor") { switch (key) {
metadataElement.value = value ?? "#FFFFFF"; case "backgroundColor":
} else { metadataElement.value = value ?? "#FFFFFF";
if (key === "swfVersion") { break;
case "uncompressedLength":
metadataElement.textContent = `${value >> 10}Kb`;
break;
case "swfVersion":
document.getElementById( document.getElementById(
"flashVersion" "flashVersion"
).textContent = swfToFlashVersion[value]; ).textContent = swfToFlashVersion[value];
} // falls through and executes the default case as well
if (key === "uncompressedLength") { default:
metadataElement.textContent = `${value >> 10}Kb`;
} else {
metadataElement.textContent = value; metadataElement.textContent = value;
} break;
} }
} }
} }