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

JavaScript best practices #4

Closed
emiliazm opened this issue May 2, 2022 · 0 comments
Closed

JavaScript best practices #4

emiliazm opened this issue May 2, 2022 · 0 comments

Comments

@emiliazm
Copy link
Owner

emiliazm commented May 2, 2022

  • Give a more clear name to variables:

    todoList/src/ui.js

    Lines 8 to 38 in 17c7503

    const labelElement = e.target.parentNode;
    labelElement.classList.add('editing', 'erasing');
    const taElement = e.target.nextElementSibling;
    taElement.focus();
    };
    const uiBlurTextArea = (e) => {
    const lblElement = e.target.previousElementSibling;
    lblElement.innerHTML = e.target.value;
    const taElement = e.target.parentNode;
    const { taskid } = e.target.parentNode.dataset;
    setTimeout(() => {
    taElement.classList.remove('editing', 'erasing');
    }, 2000);
    updateTask(taskid, e.target.value);
    };
    // remove item
    const uiRemoveTask = (e) => {
    const { taskid } = e.target.parentNode.dataset;
    deleteTask(taskid);
    const liElement = e.target.parentNode;
    liElement.remove();
    const lis = document.querySelectorAll('.list-items');
    const tasks = getTasks();
    lis.forEach((e) => {
    e.dataset.taskindex = tasks.find((ee) => ee.id === Number(e.dataset.taskid)).index;
    });
    };

    todoList/src/ui.js

    Lines 91 to 93 in 17c7503

    const cbElement = liToTasks.querySelector('.check-box');
    cbElement.checked = task.isCompleted;
    cbElement.onclick = uiCheckStatus;

    const lis = document.querySelectorAll('.list-items');
@emiliazm emiliazm closed this as completed May 4, 2022
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

No branches or pull requests

1 participant