-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code and add utils module folder and files to clean up the c…
…ode base.
- Loading branch information
1 parent
14f45f2
commit 3cc0c24
Showing
4 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-disable import/extensions */ | ||
import getElement from './utils/getElement.js'; | ||
import updateCount from './utils/updateCount.js'; | ||
|
||
const numbers = [...getElement('.number')]; | ||
|
||
numbers.forEach((number) => { | ||
updateCount(number); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* eslint-disable comma-dangle */ | ||
const getElement = (selection) => { | ||
const element = document.querySelectorAll(selection); | ||
|
||
if (element) { | ||
return element; | ||
} | ||
throw new Error( | ||
`Please verify selected ("${selection}"), no such element exist!` | ||
); | ||
}; | ||
|
||
export default getElement; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const updateCount = (el) => { | ||
const value = +el.dataset.value; | ||
const increment = Math.ceil(value / 1000); | ||
let initialValue = 0; | ||
|
||
const increaseCount = setInterval(() => { | ||
initialValue += increment; | ||
|
||
if (initialValue > value) { | ||
el.textContent = `${value}+`; | ||
clearInterval(increaseCount); | ||
return; | ||
} | ||
el.textContent = `${initialValue}+`; | ||
}, 1); | ||
}; | ||
|
||
export default updateCount; |