Last active
October 10, 2019 16:00
-
-
Save NyaGarcia/d6a7fd9980af4957decd36bc341d1e33 to your computer and use it in GitHub Desktop.
Extracting logic from a complex function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function startProgram() { | |
if (!window.indexedDB) { | |
throw new Error("Browser doesn't support indexedDB"); | |
} | |
initDatabase(); | |
setListeners(); | |
printEmployeeList(); | |
} | |
function initDatabase() { | |
let openRequest = indexedDB.open('store', 1); | |
openRequest.onerror = () => { | |
console.error('Error', openRequest.error); | |
}; | |
openRequest.onsuccess = () => { | |
let db = openRequest.result; | |
}; | |
} | |
function setListeners() { | |
document.getElementById('stat-op').addEventListener('click', () => {}); | |
document.getElementById('pre2456').addEventListener('click', () => {}); | |
document.getElementById('cpTagList100').addEventListener('change', () => {}); | |
document.getElementById('cpTagList101').addEventListener('click', () => {}); | |
document.getElementById('gototop').addEventListener('click', () => {}); | |
document.getElementById('asp10').addEventListener('click', () => {}); | |
} | |
async function printEmployeeList() { | |
const employees = await getEmployeeList(); | |
document.getElementById('employeeSelect').innerHTML = formatEmployeeList(employees); | |
} | |
function formatEmployeeList(employees) { | |
return employees.reduce( | |
(content, employee) => content + employee.name + '<br>', | |
'' | |
); | |
} | |
function getEmployeeList() { | |
return fetch('employeeList.json').then(res => res.json()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment