Skip to content
26 changes: 23 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
export default class App {
constructor($target) {
console.log($target);
import NewTodoInput from './components/NewTodoInput.js';
import Component from './core/component.js';
import State from './core/State.js';
import { $ } from './utils/utils.js';

export default class App extends Component {
setState() {
this.todoList = new State([]);
}

render() {
this.mountChildren();
}

mountChildren() {
new NewTodoInput($('#new-todo-title'), {
todoList: this.todoList,
onSubmitTodo: this.onSubmitTodo,
});
}

onSubmitTodo() {
console.log(this.todoList);
}
}
20 changes: 20 additions & 0 deletions src/components/NewTodoInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Component from '../core/component.js';

export default class NewTodoInput extends Component {
render() {}

bindEvents() {
this.$target.addEventListener('keyup', ({ key }) => {

Choose a reason for hiding this comment

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

(질문) 여기서 ({ key }) 이렇게 하는 것과 ( key ) 이렇게 하는 것은 차이가 없겠지요?
기초적일 수 있지만 여쭈어 보아요.

Copy link
Author

Choose a reason for hiding this comment

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

음 destructuring 키워드를 찾아보시면 될 것같아요! 차이는 없지만 전 가독성 측면에서 destructuring을 즐겨써요

if (key !== 'Enter') return;
this.addTodo(this.$target.value);
this.$target.value = '';
this.props.onSubmitTodo();
});
}

addTodo(todo) {
const todoList = this.props.todoList.get();
todoList.push(todo);
this.props.todoList.set(todoList);
}
}