-
Notifications
You must be signed in to change notification settings - Fork 218
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
[10기 곽창섭] TodoList with CRUD #218
base: changsubkwak
Are you sure you want to change the base?
Conversation
ChangSubKwak
commented
Jul 12, 2021
- 기능 구현에만 집중
- 리팩토링, 코드 분리, 클린코드 지향 작업 못하였음
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.
한 주 동안 미션 완료하시느라 수고많으셨습니다 😆😆
한 주 간의 고민의 흔적이 아주 느껴집니다!
차후에는 한 곳에 모든 기능을 넣는 것보다 모듈 별로 조금 나누고 바닐라자바스크립트로
상태관리까지 활용하시면 더 좋은 코드가 될 것 같습니다!
차주까지 같이 화이팅해요! 💯
itemHTML += "</div>"; | ||
itemHTML += "<input class='edit' value='" + todoObj.value + "' />"; | ||
itemHTML += "</li>"; | ||
|
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.
백틱(`)으로 템플릿 리터럴을 사용을 추천드립니다😸
이를 사용하면, 기존의 따옴표 방식에서는, + 연산자를 사용하지 않고
않에 표현식을 작성할 수 있습니다 ㅎㅎ
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.
넵, 참고하겠습니다.
for (let i = 0 ; i < todoData.length ; i++) { | ||
addTodoItem(todoData[i], true); | ||
} |
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.
배열순회를 목적으로 하신다면 for문보다는 map이나 foreach의 사용을 추천드립니다ㅎㅎ
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.
작성하신 코드 잘봤습니다! 한 주 동안 고생하셨습니다.
let todoView = document.getElementById("todo-list"); | ||
let todoData = JSON.parse(localStorage.getItem('todoData')) ?? []; |
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.
변하는 값이 아니라면 let 보다는 const를 사용하는게 좋습니다! let은 나중에 변수 할당해야할 필요가 있거나 등의 꼭 필요한 이유가 있는 경우 아니고서야 기본적으로 const를 사용한다고 보시면됩니다. 이유는 계속해서 한개의 변수에 다른 값을 할당하면 디버깅이나 유지보수 측면에서 추적이 힘들 수 있다고 알고있습니다!
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.
넵, 알겠습니다. ^^
for (let i = 0 ; i < todoData.length ; i++) { | ||
addTodoItem(todoData[i], true); | ||
} |
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.
for 보다는 array method나 for in for of를 사용하는 것도 좋아보입니다!
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.
향후, 개선된 코드를 보여드리도록 하겠습니다.
type : todoObj.type, | ||
value : todoObj.value, | ||
}); | ||
localStorage.setItem('todoData', JSON.stringify(todoData)); |
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.
setitem getitem같은걸 유틸로 분리해서 사용하면 좋을 것 같아요!
if (e.key === "Enter" && newTodoTitle.value !== '') { | ||
let todoObj = { | ||
isComplete : "false", | ||
type : "view", | ||
value : newTodoTitle.value, | ||
} | ||
addTodoItem(todoObj, false); | ||
newTodoTitle.value = ''; | ||
} |
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.
&&로 체크하기 보다는 거짓 조건을 먼저 달아서 함수를 끝내는 것도 방법입니다
if (newTodoTitle.value === '') return
if (e.key === "Enter") {
#code
}
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.addEventListener("dblclick", (e) => { | ||
let li = e.target.parentElement.parentElement; | ||
li.classList.add("editing"); | ||
li.addEventListener('keyup', (e2) => { |
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.
e2보다는 좀 더 명확한 변수명을 사용하는게 좋을 것 같아요!
e.target.setAttribute("false", ""); | ||
e.target.removeAttribute("checked"); |
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.
attribute를 사용할 때
e.target.checked = true
e.target.checked = 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.
전체적으로 고생하신 흔적이 보이는 코드였습니다!
Array.proptotype이나 slice 를 자연스럽게 사용하시는 걸 보니 JavaScript에 대해 잘 이해하고 사용하시 는 것 같아 배울 점이라고 생각합니다.
날이 더운데 코드 구현하시느라 고생 많으셨습니다 ㅎㅎ
let itemHTML = ""; | ||
itemHTML += "<li id='" + id + "' class='" + isComplete + "'>"; | ||
itemHTML += "<div class='" + todoObj.type + "'>"; | ||
itemHTML += "<input class='toggle' type='checkbox' id='" + id + "' " + isChecked + " />"; | ||
itemHTML += "<label class='label'>" + todoObj.value + "</label>"; | ||
itemHTML += "<button class='destroy' id='" + id + "'></button>"; | ||
itemHTML += "</div>"; | ||
itemHTML += "<input class='edit' value='" + todoObj.value + "' />"; | ||
itemHTML += "</li>"; |
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.
`<li >
<div class="view">
<input class="toggle" type="checkbox" data-node-id=${todo.idx} />
//중략
</li>`
이런식으로 백틱(
)` 을 이용해서 한번에 기입하는 것도 좋을 것 같아요 ㅎㅎ
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.
넵, 감사합니다.