Skip to content

Commit

Permalink
mebbe only onchange
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpizza committed May 22, 2024
1 parent cc5d9b0 commit 34c6e39
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ <h1>Books read since 1998</h1>
const YEARS = Array(CURRENT_YEAR - FIRST_YEAR + 1).fill().map((_, i) => FIRST_YEAR + i).reverse()
const COLUMNS = ['Year', 'Title', 'Author']

function debounce(action, delay = 100) {
let timeoutID

return (...args) => {
clearTimeout(timeoutID)
timeoutID = setTimeout(() => {
action.apply(this, args)
}, delay)
}
}

Promise.all(
YEARS.map(year => {
return new Promise((resolve) => {
Expand Down Expand Up @@ -108,7 +97,7 @@ <h1>Books read since 1998</h1>
const filter = document.querySelector('input[name=filter]')
filter.value = ''

filter.addEventListener('input', debounce(({ target: { value } }) => {
filter.addEventListener('change', ({ target: { value } }) => {
if (value.trim() === '') {
table.querySelectorAll('tr').forEach(tr => {
tr.removeAttribute('style')
Expand All @@ -125,7 +114,7 @@ <h1>Books read since 1998</h1>
})
tr.style.display = !isVisible ? 'none' : ''
})
}))
})

document.body.appendChild(table)
filter.removeAttribute('style')
Expand Down

0 comments on commit 34c6e39

Please sign in to comment.