Skip to content

Commit 30c3404

Browse files
committed
refactor: todo list 배열 타입 추가
1 parent 9c19859 commit 30c3404

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

src/App.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import TodoForm from "./components/TodoForm.js";
33
import TodoList from "./components/TodoList.js";
44
import TodoCount from "./components/TodoCount.js";
55
import { setItem } from "./utils/storage.js";
6-
import { TodoCount as TodoCnt, TodoItem } from "./types/todo.js";
6+
import { TodoCount as TodoCnt, TodoList as TodoLi } from "./types/todo.js";
77

88
export default class App {
99
private readonly todoList: TodoList;
1010
private readonly todoCount: TodoCount;
1111

1212
constructor(
1313
private readonly $target: HTMLElement,
14-
private readonly initialState: TodoItem[],
14+
private readonly initialState: TodoLi,
1515
private readonly initialCount: TodoCnt
1616
) {
1717
new Header($target, "Todo List");
@@ -28,16 +28,16 @@ export default class App {
2828
);
2929

3030
this.todoList = new TodoList(
31-
(state: TodoItem[]) => this.#updateCount(state)
3231
$target,
3332
initialState,
33+
(state: TodoLi) => this.#updateCount(state)
3434
);
3535

3636
this.todoCount = new TodoCount($target, initialCount);
3737
}
3838

3939
// 카운트 업데이트
40-
#updateCount(todoList: TodoItem[]) {
40+
#updateCount(todoList: TodoLi) {
4141
const done = todoList.filter((todo) => todo.isCompleted).length;
4242
const nextState = { total: todoList.length, done };
4343
this.todoCount.setState(nextState);

src/components/TodoList.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { setItem } from "../utils/storage.js";
22
import validation from "../utils/validation.js";
3-
import { TodoItem } from "../types/todo.js";
3+
import { TodoList as TodoLi } from "../types/todo.js";
44

55
export default class TodoList {
6-
state: TodoItem[];
6+
state: TodoLi;
77
private readonly $todoList = document.createElement("div");
88

99
constructor(
1010
private readonly $target: HTMLElement,
11-
private readonly initialState: TodoItem[],
12-
private readonly updateCount: (state: TodoItem[]) => void
11+
private readonly initialState: TodoLi,
12+
private readonly updateCount: (state: TodoLi) => void
1313
) {
1414
$target.appendChild(this.$todoList);
1515

@@ -44,7 +44,7 @@ export default class TodoList {
4444
});
4545
}
4646

47-
setState(nextState: TodoItem[]) {
47+
setState(nextState: TodoLi) {
4848
const newState = validation.state(nextState);
4949
this.state = newState;
5050
setItem("todo", JSON.stringify(newState));

src/types/todo.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
export interface TodoItem {
21
export type StorageKey = "todo" | "count";
32

3+
export type TodoList = TodoItem[];
4+
5+
interface TodoItem {
46
text: string;
57
isCompleted: boolean;
68
}
79

810
export interface TodoCount {
911
total: number;
1012
done: number;
11-
}
13+
}

src/utils/validation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { TodoItem } from "../types/todo.js";
1+
import { TodoList } from "../types/todo.js";
22

33
const validation = {
4-
state(todoList: TodoItem[]) {
4+
state(todoList: TodoList) {
55
return todoList.filter(
66
(todo) =>
77
typeof todo?.text === "string" && typeof todo?.isCompleted === "boolean"

0 commit comments

Comments
 (0)