-
Notifications
You must be signed in to change notification settings - Fork 217
[10๊ธฐ Tami] TodoList with CRUD #217
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: ink-0
Are you sure you want to change the base?
Conversation
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.
Tami๋, 1์ฃผ์ฐจ ๊ณผ์ ๋๋ฌด ์๊ณ ๋ง์ผ์
จ์ต๋๋ค ๐
1์ฃผ์ฐจ์ PR ์ฌ๋ฆฌ์
จ๋จ ๊ฒ ๋ง์ผ๋ก๋ ๋๋จํ์ญ๋๋ค! ๐
๋จ์ ๊ณผ์ ๋ ํจ๊ป ์ด์ฌํ ํด๋ด ์๋ค! ํ์ดํ !!
src/js/TodoApp.js
Outdated
const prevIdx = this.state.todoes[this.state.todoes.length - 1].idx; | ||
|
||
const newTodo = { | ||
idx: prevIdx + 1, | ||
content: contents, | ||
state: '', | ||
edit: '', | ||
}; | ||
this.state.todoes.push(newTodo); | ||
|
||
this.setState({ | ||
...this.state, | ||
}); | ||
}, |
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.
์ด ๋ถ๋ถ์ ๋ฐ๋ก ํจ์๋ฅผ ๋ง๋ค์ด ์ฃผ๋๊ฒ ์ข์ ๊ฒ ๊ฐ์์! :)
ex) handleAdd
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.
๋ค์ด๋ฐ๊น์ง ๊ฐ์ฌํฉ๋๋ค ใ ใ
src/js/TodoApp.js
Outdated
todoCount.setState(this.state.todoes); | ||
}; | ||
|
||
new TodoInput({ |
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 todoList = new TodoList({
$app,
initialState: this.state.todoes,
});
const todoCount = new TodoCount({
$app,
initialState: this.state.count,
});
TodoList, TodoCount์ ๋ค๋ฅด๊ฒ ์ธ์คํด์ค๋ฅผ ์์ฑ ํ ๋ 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.
์ผ๋จ์ ํ ๋นํ ํ์ ๋ฐ๋ก setState
ํ ํ์๊ฐ ์๋ค๊ณ ์๊ฐํด ๊ทธ๋ ๊ฒ ํ๋๋ฐ์, ์์ผ๋ก ์ถ๊ฐ ๊ธฐ๋ฅ์ ๊ตฌํํ๋ฉด์ ์ด๋ป๊ฒ ๋ ์ง๋ ๋ชจ๋ฅด๊ฒ ๋ค์ ..^^
src/js/TodoCount.js
Outdated
|
||
this.render = () => { | ||
const todoCountTemplate = ` | ||
<span class="todo-count">์ด <strong>${this.state}</strong> ๊ฐ</span><ul class="filters"> |
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.
<ul class="filters">
๊ฐ๋
์ฑ์ ์ํด ๊ฐํํด์ฃผ๋๊ฒ ์ข์ ๊ฒ ๊ฐ์์! ๐
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.
์๋
ํ์ธ์ ์ด์ง์์
๋๋ค.
์ฝ๋๋ฆฌ๋ทฐ๊ฐ ์ฒ์์ด๋ผ ๋ค๋ฅธ์ฌ๋ ์ฝ๋๋ณด๋๊ฒ ์ต์ํ์ง๊ฐ ์๋ค์ ๐
๊ธฐ๋ฅ๊ตฌํ์ ์์ง ๋ค ์๋์ด๋ ์ปดํฌ๋ํธ๊ฐ ์ ๋๋ ์ ธ์์ด์ ๋ฆฌ๋ทฐํ๋ฉด์ ๋ง์ด ๋ฐฐ์ ์ต๋๋ค
@@ -0,0 +1,2 @@ | |||
import TodoApp from './src/js/TodoApp.js'; | |||
new TodoApp(document.querySelector('.App')); |
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.
main ์ ์ฒด๋ฅผ ๋๊ฒจ์ฃผ๋ ๊ฑด ์๊ฐ ๋ชปํด๋ดค๋๋ฐ HTML์ด ํ๊ฒฐ ๋ ๊น๋ํด์ง๋ค์! ํ๋ ๋ฐฐ์๊ฐ๋๋ค ๐
src/js/TodoItem.js
Outdated
this.state = nextState; | ||
this.render(); | ||
}; | ||
this.render = () => { |
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๋ฅผ ๋ฐ๋ก ๋ ์ด์ ๊ฐ ์์ผ์ ๊ฐ์? ๊ทธ๋ ๊ฒ๋ ์์ง ๋ชปํด๋ด์ ใ ใ ใ ๊ถ๊ธํ๋ค์
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.
์ฌ์ค ์ ๊ฐ ๋ค๋ฅธ ์ํ๊ด๋ฆฌ ๋ธ๋ก๊ทธ๋ฅผ ๋ง์ด ์ฐธ๊ณ ํด์ ๋ง๋๋๋ผ ๋น์ทํด ์ก๋๋ฐ eazisilver ๋์ ์ฝ๋๋ ํ๋ฒ ๋ณด๊ณ ๋ค๋ฅธ์ ์ ์ฐพ์๋ณด๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค ใ ใ
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.
์ ์ฝ์์ต๋๋ค! ์ ์ฒด์ ์ผ๋ก ์ดํดํ๊ธฐ ์ฝ๊ฒ ์ ์ง์ฌ์ ธ ์๋ ๊ฒ ๊ฐ์๋ฐ templated์ ๊ฐ ์ปดํฌ๋ํธ์์ ๋ฐ๋ก๋ฐ๋ก ์์ฑํ๋ ๋ฐฉ์๋ณด๋ค๋ TodoApp์์ ๊ฐ ์ปดํฌ๋ํธ์ target์ ํด๋นํ๋ ์๋ฆฌ๋จผํธ๋ฅผ template์ผ๋ก renderํ๊ณ ๊ฐ ์ปดํฌ๋ํธ ๊ฐ์ฒด ์์ฑ๊ณผ ํจ๊ป target๊ฐ์ ๋๊ฒจ์ฃผ๋ ๋ฐฉ์์ ์ด๋จ๊น์? ์ฝ๋ ์ถ์ํ์ ์ ๊ฒฝ์ ์ข ๋ ์ฐ์ ๋ค๋ฉด ๋ ์ข์ ์ฝ๋๊ฐ ๋์ฌ ๊ฒ ๊ฐ์์!
src/js/TodoCount.js
Outdated
this.state = initialState; | ||
|
||
this.$target = document.createElement('div'); | ||
this.$target.className = 'count-container'; |
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.
์ด๋ ๊ฒ ์๋ก createElement๋ฅผ ํ๋ ๋ฐฉ์๋ณด๋จ TodoApp์ template์์ ํ์ component๋ค์ ํด๋นํ๋ target์ ๋ฐฐ๋ถํด์ฃผ๋ ๋ฐฉ์์ ์ด๋จ๊น์?
const todoCount = new TodoCount({ | ||
$app, | ||
initialState: this.state.count, | ||
}); |
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๋ TodoCount์ ์ฌ์ฉํ์ค ํจ์๋ค๋ OnAdd์ฒ๋ผ ๊ฐ์ฒด์ ํ์ดํ ํจ์ ํ์์ผ๋ก ๋๊ฒจ์ฃผ๊ฑฐ๋, ์๋๋ฉด bind(this)๋ฅผ ํด์ ๋๊ฒจ์ฃผ๋ฉด ๊ฐ์ฒด์์ state ์ถฉ๋์์ด ์ฌ์ฉ๊ฐ๋ฅํด์!
-ink-0/js-todo-list-step1/#3
[week1] checkBox ๊ตฌํ
- ink-0/js-todo-list-step1/#6
[week1] TodoList Delete ๊ตฌํ
- ink-0/js-todo-list-step1/#8
- ink-0/js-todo-list-step1/#8
- ink-0/js-todo-list-step1/#8
Week1/8/todo edit
- ์ํ ์ถ๊ฐ filterTodoes, isFilter, todoesCount - component ๋ค์ด๋ฐ ๋ณ๊ฒฝ TodoCount -> TodoFilter - ink-0/js-todo-list-step1/#10
- const ์์ฑ: ๋ฉ์ธ์ง, class data ๋ถ๋ฆฌ - ๊ฐ์ฒด ๋ฆฌํฐ๋ด ์ ์ฉ - ink-0/js-todo-list-step1/#10
Week1/10/todo filter
- ๊ทธ์ธ const ๋์น ์ํ ๊ฒ ์์ - ink-0/js-todo-list-step1/#12
-ink-0/js-todo-list-step1/#12
Week1/12/local storage
-ink-0/js-todo-list-step1/#14
[week2] GET userList
] -ink-0/js-todo-list-step1/#17
] -ink-0/js-todo-list-step1/#17
Week2/17/user list UI
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.
1์ฐจ TodoList ๋ณธ์ธ ๋ฆฌ๋ทฐ
const initialData = { | ||
todoes: [ | ||
{ | ||
idx: 0, | ||
content: 'hiEvery One', | ||
state: '', | ||
}, | ||
{ | ||
idx: 1, | ||
content: 'Im Tami', | ||
state: '', | ||
}, | ||
], | ||
todoesFiltered: [], | ||
filterState: FILTER_TYPES.ALL, | ||
todoesCount: '0', | ||
users: [], | ||
}; |
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.
์ด๊ธฐ ๋ฐ์ดํฐ๋ฅผ ๋ฐ๋ก ๋ณด๊ดํ๋ ๊ฒ์ด ์ข์์ ๊ฒ์ด๋ค.
this.state['todoes'] = resetTodoes; | ||
localStorage.clear(); | ||
localStorage.setItem('state', JSON.stringify({ ...this.state })); | ||
this.state = JSON.parse(localStorage.getItem('state')); | ||
this.setState({ | ||
...this.state, | ||
}); | ||
}; |
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.
์์ฑ ์ญ์ ์ clear
ํ setํ๋ ๋ฐฉ์๋ฐ์ ์์๋์ง ๊ณ ๋ฏผํ ํ์๊ฐ ์๋ค.
const filterTodo = (filterType) => { | ||
const { todoes } = this.state; | ||
if (filterType === FILTER_TYPES.ALL) { | ||
this.setState({ | ||
...this.state, | ||
filterState: FILTER_TYPES.ALL, | ||
todoesCount: todoes.length, | ||
}); | ||
} else if (filterType === FILTER_TYPES.COMPLETE) { | ||
const completedTodoes = todoes.filter( | ||
(todo) => todo.state === FILTER_TYPES.COMPLETE | ||
); | ||
|
||
this.setState({ | ||
...this.state, | ||
todoesFiltered: completedTodoes, | ||
filterState: FILTER_TYPES.COMPLETE, | ||
todoesCount: completedTodoes.length, | ||
}); | ||
} else if (filterType === FILTER_TYPES.ACTIVE) { | ||
const activeTodoes = todoes.filter( | ||
(todo) => todo.state !== FILTER_TYPES.COMPLETE | ||
); | ||
this.setState({ | ||
...this.state, | ||
todoesFiltered: activeTodoes, | ||
filterState: FILTER_TYPES.ACTIVE, | ||
todoesCount: activeTodoes.length, | ||
}); |
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.
์ฝ๋ ์ค๋ณต์ด ๋ง๋ค.
setState๋ฅผ ํ๋ ๋ถ๋ถ์์ ์ค๋ณต์ ํด๊ฒฐํ ๋ฐฉ์์ด ํ์ํ๋ค
$nodeTodoList.addEventListener('click', (e) => { | ||
const $node = e.target; | ||
|
||
if ($node.className === TODO_ITEM_CLASS.TOGGLE) { | ||
this.toggleTodoItem($node); | ||
} | ||
if ($node.className === TODO_ITEM_CLASS.DESTROY) { | ||
this.deleteTodoItem($node); | ||
} | ||
|
||
if ($node.className === TODO_ITEM_CLASS.EDIT) { | ||
this.editTodoItem($node); | ||
} |
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.
์ด๋ฒคํธ early return ์ด ํ์ํ๋ค
๐ ํ๊ณ
๊ธฐํ ์ฌ์ ์ผ๋ก ์ธํด ์๊ตฌ์ฌํญ์ ๊ฑฐ์ ์๋ฃํ์ง ๋ชปํ์ต๋๋ค. ๐ข
์ด๋ฒ์ฃผ ๋ด๋ด ์คํผ๋๋ฅผ ๋ด์ ์ด๋ฒ์ฃผ ๋ฏธ์ ๊ณผ ์ ๋ฒ์ฃผ ๋ฏธ์ ์ ์ดํํ ์์ ์ ๋๋ค
๐ ์งํ ์ํฉ
๐ฏ ์๊ตฌ์ฌํญ