Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Last active October 10, 2019 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NyaGarcia/d6a7fd9980af4957decd36bc341d1e33 to your computer and use it in GitHub Desktop.
Save NyaGarcia/d6a7fd9980af4957decd36bc341d1e33 to your computer and use it in GitHub Desktop.
Extracting logic from a complex function
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