-
Notifications
You must be signed in to change notification settings - Fork 4
[Mission001] todolist crud #6
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
base: master
Are you sure you want to change the base?
Conversation
mission001/jisun/js/app.js
Outdated
| @@ -0,0 +1,15 @@ | |||
| import { todoListData, todoIdCount } from './store/store.js'; | |||
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.
redux store 을 생각하시고 파일 경로를 /store/store.js 로 하신건가요?
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.
리덕스 뿐만 아니라 vuex, mobX 등 상태 관리 라이브러리가 데이터 저장소로 store라는 이름을 쓰는 걸 생각하고 폴더명/파일명을 정했습니다. 딱히 리덕스 하나만을 염두에 두고 만든 건 아닙니다.
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.
아하 ㅎㅎ 그렇군요!! 친절한 답변 감사합니다^^
mission001/jisun/js/app.js
Outdated
| TodoInput(todoListData); | ||
| TodoCount(todoListData, todoCount); | ||
|
|
||
| // 선택한 텝에 따라 랜더링 다시하기 'ㅁ' |
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.
'ㅁ' 요 이모티콘은 제거해주셔도 좋을것 같아요 ㅎㅎ
|
|
||
| export const renderCount = (data, selector) => { | ||
| selector.innerHTML = `총 <strong>${data.length}</strong> 개`; | ||
| } No newline at end of file |
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.
end of new line을 추가해주세요. app.js 파일 같은 경우는 두줄이 추가 되었네요 ㅎ
| renderCount(data, todoCount); | ||
| } | ||
|
|
||
| export const renderCount = (data, selector) => { |
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.
여기 파라미터를 selector로 받는 다면, const todoCount = document.getElementById("todoCount"); 여기에서 todoCount도 $selector 같은 이름으로 바꿔주면 좀 더 명확해질 듯 합니다
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.
고생하셨습니다!! 제 생각엔 이렇게 하면 어떨까 싶은 것들에 대해 코멘트 남겨봤습니다!!
그리고 궁금한 것이 있습니다.
컴포넌트를 new 키워드를 통해 객체로 만들지 않고, 매번 함수를 호출하는 방식으로 하시는 이유가 따로 있으신가요?
코드를 보면, 예를들어 renderTodoList() 를 호출하는 코드가 몇몇 보입니다. 이 함수를 호출하게 되면, 호출할때마다 이벤트 등록이 계속에서 실행하게 될텐데, 이는 낭비이지 않을까요..??
그리고 구조 잡는 것은 저 역시 쉽지 않은 부분 이지만, 같이 스터디중인 다른 분들은 어떻게 구조를 잡았는지 살펴보면 도움이 많이 되지 않을까 생각합니다..!!
|
|
||
| const todoList = document.getElementById("todoList"); | ||
|
|
||
| export function TodoList (data) { |
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.
이 소스코드의 메인 함수인 듯한데, export 보다는 export default 로 하는 것은 어떨까요?
| } | ||
|
|
||
| // 초기 데이터에 따라 todoList render | ||
| export const renderTodoList = (list) => { |
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.
onEditMode() 에서는 매개변수를 data 로 네이밍을 하셨는데, 여기서는 list 라고 하셨습니다. 동일한 데이터를 전달하는데, 일관되게 네이밍을 하시는 것을 어떨까요?
| todoList.innerHTML = `<li>Todo List가 비어있습니다</li>`; | ||
| } else { | ||
| list.forEach(data => { | ||
| todoList.innerHTML += `<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.
todoList.innerHTML 가 list 의 크기만큼 호출하게 되고, 호출되는 만큼 렌더링이 이뤄질텐데, 이는 불필요하게 렌더링을 많이 하게되는게 아닌가 싶습니다. HtmlString 을 누적시켜서 만든다음에 innerHTML 을 한번만 호출하는 방식으로 진행하는 것은 어떨까요?
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.
@YongHoonJJo 저도 용훈님이 리뷰 단 내용을 남겨놓고 싶었는데,, 어떻게 말로 잘 설명해야할지 모르던 찰나에 용훈님이 달아주셧네요 ㅎㅎ
|
|
||
| // 초기 데이터에 따라 todoList render | ||
| export const renderTodoList = (list) => { | ||
| todoList.innerHTML = ''; |
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-else 문에 의해 innerHTML 이 실행이 됩니다. 이 위치에서 todoList.innerHTML = ''; 는 없어도 되지 않을까요?
| setTodoIdCount(todoIdCount + 1); | ||
| console.log(todoListData) | ||
|
|
||
| checkbox.addEventListener("change", e => { |
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.
onComplete(e) 함수 자체가 이벤트 핸들러인 것 같은데, checkbox.addEventListener("change", onComplete) 와 같이 하는 것은 어떨까요?
| input.addEventListener("keydown", e => { | ||
| if (e.key === "Enter") { | ||
| if (input.value === "") { | ||
| alert("값을 입력해주세요 !"); |
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.
수정했습니다! 감사합니다!
|
|
||
| editInput.style.display = "block"; | ||
| editInput.addEventListener("keydown", e => { | ||
| if (e.keyCode === 27) { |
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.
다른 곳에서는 e.key 를 사용하셨는데, e.keyCode 와 혼용하고 계신 이유가 따로 있으신가요?
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.
keyCode deprecated 되었다고, 제 코드에 동준님이 리뷰를 달아주셨었습니다 ㅎ KeyboardEvent를 참고하시면 될것 같다고도 리뷰 달아주셨었습니다. ㅎㅎ
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.
keyCode가 deprecated되었기 때문에... e.key를 사용하려 했는데요, esc는 e.key에 잡히지 않더라구요.. 그래서 어쩔 수 없이 keyCode를 사용하게 되었네요.
이왕 이렇게 된 거 e.keyCode로 전부 통일할까 고민 중입니다.
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.
code 비교할때 "esc"말고 "Escape"로 찾으면 잡을 수 있을 거에요.
동준님이 링크주신 아래 사이트 가시면 확인가능해요.
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
| todoList.innerHTML = `<li>Todo List가 비어있습니다</li>`; | ||
| } else { | ||
| list.forEach(data => { | ||
| todoList.innerHTML += `<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.
@YongHoonJJo 저도 용훈님이 리뷰 단 내용을 남겨놓고 싶었는데,, 어떻게 말로 잘 설명해야할지 모르던 찰나에 용훈님이 달아주셧네요 ㅎㅎ
|
|
||
| editInput.style.display = "block"; | ||
| editInput.addEventListener("keydown", e => { | ||
| if (e.keyCode === 27) { |
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.
keyCode deprecated 되었다고, 제 코드에 동준님이 리뷰를 달아주셨었습니다 ㅎ KeyboardEvent를 참고하시면 될것 같다고도 리뷰 달아주셨었습니다. ㅎㅎ
|
|
||
| if (e.keyCode === 13) { | ||
| if (prevValue !== editInput.value) { | ||
| let i = 0; |
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.
이 부분을 Javascript map 함수를 사용하여 좀 더 가독성있게 코드를 바꿔봐도 좋을 것 같습니다^^
map
| editInput.style.display = "none"; | ||
| } | ||
|
|
||
| if (e.keyCode === 13) { |
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 문이 중첩되기 시작하면, 가독성이 안좋아지는 개인적인 느낌이 들어서 아래와 같은 문법을 선호합니다.
if (e.keyCode === 13 && prevValue !== editInput.value)
mission001/jisun/js/util/utils.js
Outdated
|
|
||
| let selectedTodoData = []; | ||
|
|
||
| if ( |
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.
onSelectTab 안에서 여러가지 기능을 담당하고 있는 것 같습니다. 요 부분은 해당 기능만을 위한 함수를 만들어서 따로 분리 시켜도 좋을것 같아요^^
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.
const checkSelectTab = () => {
if (selectedTab.id === status.COMPLETED || selectedTab.id === status.NEED_TODO) {
for (let i = 0; i < data.length; ++i) {
if (data[i].status === selectedTab.id) selectedTodoData.push(data[i]);
}
return renderTodoList(selectedTodoData);
}
return renderTodoList(data);
}
이런식으로요 ㅎㅎ 함수명은 딱히 생각 안나서ㅎ, 그러면 else 문을 사용하지 않고도 return 으로 작성 가능 할 것 같군요!
StellaKim1230
left a comment
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.
코드 잘 봤습니다^^.
궁금하신것 있으시면 언제든 코멘트 남겨주세요 ㅎㅎ
mission001/jisun/index.html
Outdated
| <div class="main"> | ||
| <input class="toggle-all" type="checkbox" id="" /> | ||
| <ul id="todoList" class="todo-list"></ul> | ||
| <!-- <ul id="todo-list" class="todo-list"> |
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.
주석처리는 그냥 삭제해주셔도 좋을것 같아요 ㅎㅎ
amorfati0310
left a comment
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.
수고 많으셨어요 리뷰가 도움이 되면 좋겟네요
| background-image: url("data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23bddad5%22%20stroke-width%3D%223%22/%3E%3Cpath%20fill%3D%22%235dc2af%22%20d%3D%22M72%2025L42%2071%2027%2056l-4%204%2020%2020%2034-52z%22/%3E%3C/svg%3E"); | ||
| } | ||
|
|
||
| .todo-list li label { |
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.
여유가 되시면 sass로 진행을 하셔도 좋을 것 같습니다
nested , import 등 css 로 하는 것보다 많은 장점이 있습니다 :)
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.
앗 저 이 파일 따로 주어지는 거라고 이제 알았네요 ... 앞에 얘기 무시해주세영 ㅎㅎ;;
| }; | ||
|
|
||
| export const putData = async (username, id) => { | ||
| await fetch(`${URL}/${username}/${id}/toggle`, { |
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.
api 함수들의 return 값을 줘야 나중에 성공이나 에러 처리를 할 때 response 값을 파악할 수 있지 않을까요?.?
| import { getTodoListData } from './store/store.js'; | ||
|
|
||
| // 데이터 로드, 컴포넌트 랜더링 | ||
| getTodoListData(() => { |
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.
개인적으로는 getTodoListData 이 함수 이름이 조금 어색해보였습니다. 데이터를 가지고 오는 느낌이 아니고 뷰를 초기화 하고 뷰데이터랑 sync 를 맞춰주는 것 같아서요
ex) initViewComponents 같은 네이밍이 더 적절하지 않을까요?
| } | ||
|
|
||
| const render = data => { | ||
| input.addEventListener("keydown", e => { |
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.
컴포넌트마다 render , setState 같은 이름을 가져가는게 좋은데요
이 render 함수가 계속 이벤트리스너를 setState가 발생할 때마다 중복으로 걸어주는 역할을 하지는 않나 싶습니다
이벤트 바인딩과 렌더만 하는 부분을 분리하면 어떨까요?
아 그러고보니 렌더함수가 제가 말한 의미에 렌더함수라면
TodoInput 같은 부분에서 view-data-binding 연결되는 부분이 없어서 렌더함수가 필요하지 않은 것 같긴 하네요
| const toggles = document.getElementsByClassName("toggle"); | ||
| const deleteBtns = document.getElementsByClassName("destroy"); | ||
|
|
||
| for (let i = 0; i < toggles.length; ++i) { |
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.
각각의 버튼마다 이벤트를 걸기보다 컨테이너에서 이벤트를 걸어서 버블링을 통해서 감지하는 이벤트 전파에 대해서 알아보시면 좋을 것 같습니다 :)
| }; | ||
|
|
||
| export const onComplete = e => { | ||
| const list = e.target.parentElement.parentElement; |
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.
혹시 dom구조가 바뀌게 되는 경우 e.target.parentElement.parentElement 말고 대안이 있을지 알아보시면 좋을 것 같습니다
|
|
||
| editInput.style.display = "block"; | ||
| editInput.addEventListener("keydown", e => { | ||
| if (e.keyCode === 27) { |
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.
2, 27, 13 등 매직넘버들을 상수로 관리해주면 더 좋을 것 같습니다 :)
| let selectedTodoData = []; | ||
|
|
||
| if (selectedTab.id === 'completed') { | ||
| for (let i = 0; i < data.length; ++i) { |
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 함수를 통해서 for문을 더 가독성있게 고쳐보셔도 좋을 것 같아요 :)
| input.addEventListener("keydown", e => { | ||
| onAddData(e, data); | ||
| }); | ||
| }; | ||
|
|
||
| const onAddData = (e, data) => { | ||
| if (e.keyCode === 13) { |
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.
클릭이벤트에서 한글을 넣고 입력시 중복 입력이 되었었다고 저번 미팅때 들었습니다.
저도 같은 현상이 발생하여 찾아본 몇가지 경우의 수를 공유드립니다. 원인은 e.keyCode가 곧 안쓰인다고 해서 e.code로 변경 후에 생겼는데요. 아래 3가지 경우의 수를 보고 참고하시면 좋을 것 같아요.
- keyup 또는 keydown 과 e.code 사용시 한글 중복입력발생,
- keypress와 e.code 사용시 한글 정상입력,
- keyup, keydown 상관없이 e.key 사용시 한글 정상입력되었습니다.
참고로 저는 용훈님이 추천한 e.key를 사용하는 걸로 해결하였습니다.
관련링크 https://ckbcorp.tistory.com/819
폴더 구조, 코드 구조를 어떻게 잡아야 하는지가 가장 어렵네요.
순수 JS로 컴포넌트를 어떻게 짜야 좋을지,
컴포넌트에는 어떤 데이터, 함수가 들어가야 할지 고민하는 과정이 길었습니다..!