Skip to content

Commit 4fa5d9f

Browse files
committed
refactor: constructor 내부 상태값 this 접근자 삭제
1 parent e249e6a commit 4fa5d9f

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

src/App.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,26 @@ export default class App {
1414
private readonly initialState: TodoItem[],
1515
private readonly initialCount: TodoCnt
1616
) {
17-
new Header(this.$target, "Todo List");
17+
new Header($target, "Todo List");
1818

1919
new TodoForm(
20-
this.$target,
20+
$target,
2121
(text: string) => {
22-
const nextState = [...this.todoList.state, { text, isCompleted: false }];
22+
const nextState = [
23+
...this.todoList.state,
24+
{ text, isCompleted: false }
25+
];
2326
this.todoList.setState(nextState);
2427
},
2528
);
2629

2730
this.todoList = new TodoList(
28-
this.$target,
29-
this.initialState,
3031
(state: TodoItem[]) => this.#updateCount(state)
32+
$target,
33+
initialState,
3134
);
3235

33-
this.todoCount = new TodoCount(this.$target, this.initialCount);
36+
this.todoCount = new TodoCount($target, initialCount);
3437
}
3538

3639
// 카운트 업데이트

src/components/Header.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default class Header {
55
private readonly $target: HTMLElement,
66
private readonly text: string
77
) {
8-
this.$target.appendChild(this.$header);
8+
$target.appendChild(this.$header);
99
this.render();
1010
};
1111

src/components/TodoCount.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ export default class TodoCount {
88
private readonly $target: HTMLElement,
99
private readonly initialCount: TodoCnt
1010
) {
11-
this.$target.appendChild(this.$container);
11+
$target.appendChild(this.$container);
1212

13-
if (this.initialCount.total) {
14-
this.state = this.initialCount;
15-
} else this.state = { total: 0, done: 0 };
13+
if (initialCount.total) this.state = initialCount;
14+
else this.state = { total: 0, done: 0 };
1615

1716
this.render();
1817
}

src/components/TodoForm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default class TodoForm {
77
private readonly $target: HTMLElement,
88
private readonly onSubmit: (text: string) => void
99
) {
10-
this.$target.appendChild(this.$form);
10+
$target.appendChild(this.$form);
1111
this.render();
1212
}
1313

src/components/TodoList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export default class TodoList {
1111
private readonly initialState: TodoItem[],
1212
private readonly updateCount: (state: TodoItem[]) => void
1313
) {
14-
this.$target.appendChild(this.$todoList);
14+
$target.appendChild(this.$todoList);
1515

16-
if (Array.isArray(this.initialState)) this.state = this.initialState;
16+
if (Array.isArray(initialState)) this.state = initialState;
1717
else this.state = [];
1818

1919
this.render();

0 commit comments

Comments
 (0)