Skip to content
14 changes: 11 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import NewTodoInput from './components/NewTodoInput.js';
import TodoList from './components/TodoList.js';
import Component from './core/component.js';
import State from './core/State.js';
import { $ } from './utils/utils.js';
Expand All @@ -15,11 +16,18 @@ export default class App extends Component {
mountChildren() {
new NewTodoInput($('#new-todo-title'), {
todoList: this.todoList,
onSubmitTodo: this.onSubmitTodo,
onSubmitTodo: this.mountTodoList.bind(this),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^ 이렇게 바꾼 이유는 혹시 onSubmitTodo를 이 App.js 내부에서는 그려짐과 동시에 행해야 할 것이기에 명칭을 바꾼 것으로 생각됩니다만, key값은 그대로 두신 이유가 궁금해졌습니다.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

props를 받는 컴포넌트의 네임을 바꾸기 귀찮아서 그대로 뒀습니다 ㅎㅎ 큰 이유는 없었어요

});
}

onSubmitTodo() {
console.log(this.todoList);
mountTodoList() {
new TodoList($('#todo-list'), {
todoList: this.todoList,
deleteTodo: this.deleteTodo.bind(this),
});
}

deleteTodo(id) {
console.log(id);
}
}
42 changes: 42 additions & 0 deletions src/components/TodoList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Component from '../core/component.js';
import { $ } from '../utils/utils.js';
import { todoButton } from '../utils/constants.js';

export default class TodoList extends Component {
render() {
const todoList = this.props.todoList
.get()
.reduce((html, { id, todo }) => (html += this.renderTodo({ id, todo })), '');
this.$target.innerHTML = todoList;
}

renderTodo({ id, todo }) {
return `
<li class="todo" id=${id}>
<div class="view">
<input class="toggle" type="checkbox" id=${id} />
<label class="label">${todo}</label>
<button class="destroy" id=${id}></button>
</div>
<input class="edit" value="${todo}" />
</li>
`;
}

bindEvents() {
this.$target.addEventListener('click', (e) => {
console.log(1);
if (e.target.classList.contains(todoButton.TOGGLE)) {
const checkId = e.target.id;
// this.$target.removeChild(target.closest('.todo'));
e.target.closest('.todo').classList.toggle('completed');
return;
// console.log(target.closest('.todo'));
// this.props.deleteTodo(checkId);
}
e.stopPropagation();
// if (target.classList.contains(todoButton.DESTROY)) {
// }
});
}
}
10 changes: 10 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const todoButton = {
TOGGLE: 'toggle',
LABEL: 'label',
DESTROY: 'destroy',
EDIT: 'edit',
EDITING: 'editing',
COMPLETED: 'completed',
};

export { todoButton };