Skip to content

Commit 3201d20

Browse files
committed
feat: App 컴포넌트 클래스 + ts 변환
1 parent 2d8a1b3 commit 3201d20

File tree

3 files changed

+42
-32
lines changed

3 files changed

+42
-32
lines changed

src/App.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,41 @@ import TodoCount from "./components/TodoCount.js";
55
import { setItem } from "./utils/storage.js";
66
import { TodoCount as TodoCnt, TodoItem } from "./types/todo.js";
77

8-
export default function App({ $target, initialState, initialCount }) {
9-
new Header({
10-
$target,
11-
text: "Todo List",
12-
});
8+
export default class App {
9+
// todoList: TodoList;
10+
// todoCount: TodoCount;
1311

14-
new TodoForm({
15-
$target,
16-
onSubmit: (text) => {
17-
const nextState = [...todoList.state, { text, isCompleted: false }];
18-
todoList.setState(nextState);
19-
},
20-
});
12+
constructor(
13+
protected readonly $target: HTMLElement,
14+
protected readonly initialState: TodoItem[],
15+
protected readonly initialCount: TodoCnt
16+
) {
2117

22-
const todoList = new TodoList({
23-
$target,
24-
initialState,
25-
updateCount: (state) => updateCount(state),
26-
});
18+
// new TodoForm({
19+
// $target: this.$target,
20+
// onSubmit: (text: string) => {
21+
// const nextState = [...this.todoList.state, { text, isCompleted: false }];
22+
// this.todoList.setState(nextState);
23+
// },
24+
// });
2725

28-
const todoCount = new TodoCount({
29-
$target,
30-
initialCount,
31-
});
26+
// this.todoList = new TodoList({
27+
// $target: this.$target,
28+
// initialState: this.initialState,
29+
// updateCount: (state: TodoItem[]) => this.updateCount(state),
30+
// });
31+
32+
// this.todoCount = new TodoCount({
33+
// $target: this.$target,
34+
// initialCount: this.initialCount,
35+
// });
36+
}
3237

3338
// 카운트 업데이트
34-
const updateCount = (todoList) => {
35-
const done = todoList.filter((todo) => todo.isCompleted).length;
36-
const nextState = { total: todoList.length, done };
37-
todoCount.setState(nextState);
38-
setItem("count", JSON.stringify(nextState));
39-
};
39+
// updateCount(todoList: TodoItem[]) {
40+
// const done = todoList.filter((todo) => todo.isCompleted).length;
41+
// const nextState = { total: todoList.length, done };
42+
// this.todoCount.setState(nextState);
43+
// setItem("count", JSON.stringify(nextState));
44+
// };
4045
}

src/main.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,4 @@ const initialState = getItem("todo", []);
55
const initialCount = getItem("count", { total: 0, done: 0 });
66
const $app = document.querySelector("#app") as HTMLElement;
77

8-
new App({
9-
$target: $app,
10-
initialState,
11-
initialCount,
12-
});
8+
new App($app, initialState, initialCount);

src/types/todo.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface TodoItem {
2+
text: string;
3+
isCompleted: boolean;
4+
}
5+
6+
export interface TodoCount {
7+
total: number;
8+
done: number;
9+
}

0 commit comments

Comments
 (0)