-
Notifications
You must be signed in to change notification settings - Fork 213
[10기 김승훈] TodoList with CRUD #220
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: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ export default class App { | |
| this.todoInput.setEvent({ | ||
| onAdd: text => { | ||
| const todo = { | ||
| id: new Date(), | ||
| id: Date.now(), | ||
| text, | ||
| completed:false, | ||
| } | ||
|
|
@@ -35,18 +35,21 @@ export default class App { | |
| this.todoList.render(this.todoItems) | ||
| this.todoList.setEvent({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 직접 접근해서 전달하는것보다 위의 new TodoList의 파라미터로 메소드들을 넘기는 것이 더 명확할꺼같습니다. |
||
| onDelete: (event) => { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이벤트를 각 컴포넌트에서 처리할 수 있는 건 컴포넌트에서 처리 |
||
| const item = event.target; | ||
| if (!item.classList.contains('destroy')) return; | ||
| const id = Number(item.closest('li').dataset.id); | ||
| const itemIdx = this.todoItems.findIndex((i) => i.id === id); | ||
| const target = event.target; | ||
| if (!target.classList.contains('destroy')) return; | ||
| const id = Number(target.closest('li').dataset.id); | ||
| const itemIdx = this.todoItems.findIndex((item) => item.id === id); | ||
| this.todoItems.splice(itemIdx, 1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. slice대신 splice를 사용하신 이유가 있나요?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 배열 자체를 수정하려고 하다가 splice 를 사용하였는데... 생각을 해보니 filter , slice가 더 적합할 것 같습니다. |
||
| this.setState(this.todoItems); | ||
| }, | ||
| onCompleted : (event) =>{ | ||
| const item = event.target; | ||
| if (!item.classList.contains('toggle')) return; | ||
| const itemIdx = this.todoItems.findIndex((i) => i.id === id); | ||
| console.log(itemIdx) | ||
| const target = event.target; | ||
| if (!target.classList.contains('toggle')) return; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이벤트위임 방식 좋아요! |
||
| const id = Number(target.closest('li').dataset.id); | ||
| console.log(id) | ||
| const item = this.todoItems.find((todoItem) => todoItem.id === id); | ||
| item.completed = !item.completed; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. completed를 true false로 관리하는것 직관적이고 좋은것 같습니다. |
||
| this.setState(this.todoItems); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
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.
setEvent에 들어가는 함수들을 따로 빼서 리팩토링하면 더 보기 깔끔할것같아요!