Skip to content

Commit 71703be

Browse files
committed
반복되는 로직 함수 추가
1 parent 0f5b5a8 commit 71703be

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/App.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,27 @@ export default function App({ $target, initialState, initialCount }) {
1515
onSubmit: (text) => {
1616
const nextState = [...todoList.state, { text, isCompleted: false }];
1717
todoList.setState(nextState);
18+
updateCount(nextState);
1819
setItem("todo", JSON.stringify(nextState));
19-
20-
const done = nextState.filter((todo) => todo.isCompleted).length;
21-
const count = { total: nextState.length, done };
22-
todoCount.setState(count);
23-
setItem("count", JSON.stringify(count));
2420
},
2521
});
2622

2723
const todoList = new TodoList({
2824
$target,
2925
initialState,
30-
updateCount: () => {
31-
const done = todoList.state.filter((todo) => todo.isCompleted).length;
32-
const nextState = { total: todoList.state.length, done };
33-
todoCount.setState(nextState);
34-
setItem("count", JSON.stringify(nextState));
35-
},
26+
updateCount: () => updateCount(todoList.state),
3627
});
3728

3829
const todoCount = new TodoCount({
3930
$target,
4031
initialCount,
4132
});
33+
34+
// 카운트 업데이트
35+
const updateCount = (todoList) => {
36+
const done = todoList.filter((todo) => todo.isCompleted).length;
37+
const nextState = { total: todoList.length, done };
38+
todoCount.setState(nextState);
39+
setItem("count", JSON.stringify(nextState));
40+
};
4241
}

0 commit comments

Comments
 (0)