Skip to content

Commit 1c062e5

Browse files
committed
refactor: 전역 상태 main > App에서 관리하도록 변경
1 parent 30c3404 commit 1c062e5

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/App.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ import Header from "./components/Header.js";
22
import TodoForm from "./components/TodoForm.js";
33
import TodoList from "./components/TodoList.js";
44
import TodoCount from "./components/TodoCount.js";
5-
import { setItem } from "./utils/storage.js";
5+
import { setItem, getItem } from "./utils/storage.js";
66
import { TodoCount as TodoCnt, TodoList as TodoLi } from "./types/todo.js";
7-
87
export default class App {
98
private readonly todoList: TodoList;
109
private readonly todoCount: TodoCount;
10+
private readonly initialState: TodoLi;
11+
private readonly initialCount: TodoCnt;
1112

1213
constructor(
1314
private readonly $target: HTMLElement,
14-
private readonly initialState: TodoLi,
15-
private readonly initialCount: TodoCnt
1615
) {
16+
this.initialState = getItem("todo", []);
17+
this.initialCount = getItem("count", { total: 0, done: 0 });
18+
1719
new Header($target, "Todo List");
1820

1921
new TodoForm(
@@ -29,11 +31,11 @@ export default class App {
2931

3032
this.todoList = new TodoList(
3133
$target,
32-
initialState,
34+
this.initialState,
3335
(state: TodoLi) => this.#updateCount(state)
3436
);
3537

36-
this.todoCount = new TodoCount($target, initialCount);
38+
this.todoCount = new TodoCount($target, this.initialCount);
3739
}
3840

3941
// 카운트 업데이트

src/main.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
import App from "./App.js";
2-
import { getItem } from "./utils/storage.js";
3-
4-
const initialState = getItem("todo", []);
5-
const initialCount = getItem("count", { total: 0, done: 0 });
62
const $app = document.querySelector<HTMLElement>("#app");
7-
8-
$app && new App($app, initialState, initialCount);
3+
$app && new App($app);

0 commit comments

Comments
 (0)