Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

codemcu
Copy link
Collaborator

@codemcu codemcu commented Mar 3, 2019

agenda de contactos con localstorage

@codemcu codemcu requested a review from UlisesGascon March 3, 2019 20:37
@UlisesGascon UlisesGascon mentioned this pull request May 31, 2019
46 tasks
Copy link
Contributor

@UlisesGascon UlisesGascon left a 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');
Copy link
Contributor

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);
Copy link
Contributor

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) {
Copy link
Contributor

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 = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Esto da lugar a confusión, el enfoque es poco funcional. Intenta evitar las variables globales!

data.forEach(item => appendTemplate(item));
}

function appendTemplate(contactValues) {
Copy link
Contributor

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);
Copy link
Contributor

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) {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants