-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
agenda de contactos con localstorage #82
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
En general muy bien, pero sería interesante darle un repaso con lo que hemos visto estos últimos meses. Creo que podrías darle un enfoque más limpio y funcional. Aunque tecnicamete esta bien, al margen de los warnings... creo que falta un poco más de arquitectura. Pero muy bien, me gusta como enfocas el reto 😉
@@ -0,0 +1,198 @@ | |||
(function() { | |||
const inputs = document.querySelectorAll('input[type=text]'); | |||
const containerList = document.querySelector('#containerList'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document.querySelector
es infinitamente más lento que document.getElementById
.
📖 Benchmarkhttps://jsperf.com/getelementbyid-vs-queryselector/25
const buttonDelete = document.querySelector('#delete'); | ||
const buttonDeleteAll = document.querySelector('#deleteAll'); | ||
|
||
buttonSave.addEventListener('click', saveContact, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Muy buena abstracción! 👍
let contactsToStorage = []; | ||
let indexToChange = null; | ||
|
||
function onShowDeleteAllButton(show = false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onShowDeleteAllButton
y onShowDeleteButton
son super similares. Usa un closure o pasarle un argumento para evitar repetir tanto código
buttonDelete.addEventListener('click', deleteContact, false); | ||
buttonDeleteAll.addEventListener('click', deleteAllContact, false); | ||
|
||
let contactsToStorage = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data.forEach(item => appendTemplate(item)); | ||
} | ||
|
||
function appendTemplate(contactValues) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contactData
o data
o simplemente contact
pienso que sería semánticamente más esclarecedor 😉
|
||
function saveContact() { | ||
const values = _getValuesForm(); | ||
const isFormOk = _isFormOK(values); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isFormOk
la usa solo una vez.. tiene sentido crear una variable?
const PHONE_REGEX = /[0-9]+/g; | ||
const EMAIL_REGEX = /([\w]+[\-]*[0-9]*)+@(([\w]{3,})+[\.])+([a-z]{2,3})/g; | ||
|
||
if (values[0].match(NAME_REGEX) === null || values[1].match(PHONE_REGEX) === null || values[2].match(EMAIL_REGEX) === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esto debe limpiarse un poco.. con un array o similar. Enfoque más funcional
agenda de contactos con localstorage