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

Code Refactor using DRY,KISS and YAGNI #5

Open
elasfarc opened this issue Jul 19, 2021 · 0 comments
Open

Code Refactor using DRY,KISS and YAGNI #5

elasfarc opened this issue Jul 19, 2021 · 0 comments

Comments

@elasfarc
Copy link
Owner

  • These functions never used in your code, remove them
    export function taskTobeSwapped(e) {
    if (e.path[0].nodeName !== 'LI') return e.path[0].parentElement;
    return e.target;
    }
    export function exchangeElements(parent, element1, element2) {
    const clonedElement1 = element1.cloneNode(true);
    const clonedElement2 = element2.cloneNode(true);
    parent.replaceChild(clonedElement1, element2);
    parent.replaceChild(clonedElement2, element1);
    }

-You have to update the whole array every time

To-Do-list/src/todo.js

Lines 57 to 68 in 79bd6d8

updateIndex(updatedIndexArr) {
updatedIndexArr = updatedIndexArr.map((ele) => ele.title);
const output = [];
updatedIndexArr.forEach((element) => {
output.push(this.#storage.find((ele) => ele.description.trim() === element.trim()));
});
for (const i in output) {
output[i].index = parseInt(i, 10) + 1;
}
this.#storage = output;
this.updateLocalStorage();
}

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