File tree Expand file tree Collapse file tree 2 files changed +20
-18
lines changed Expand file tree Collapse file tree 2 files changed +20
-18
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { TodoCount as TodoCnt, TodoItem } from "./types/todo.js";
77
88export default class App {
99 todoList : TodoList ;
10- // todoCount: TodoCount;
10+ todoCount : TodoCount ;
1111
1212 constructor (
1313 protected readonly $target : HTMLElement ,
@@ -30,10 +30,7 @@ export default class App {
3030 ( state : TodoItem [ ] ) => this . updateCount ( state )
3131 ) ;
3232
33- // this.todoCount = new TodoCount({
34- // $target: this.$target,
35- // initialCount: this.initialCount,
36- // });
33+ this . todoCount = new TodoCount ( this . $target , this . initialCount ) ;
3734 }
3835
3936 // 카운트 업데이트
Original file line number Diff line number Diff line change 1- import validation from "../utils/validation .js" ;
1+ import { TodoCount as TodoCnt } from "../types/todo .js" ;
22
3- export default function TodoCount ( { $target, initialCount } ) {
4- validation . newTarget ( new . target ) ;
3+ export default class TodoCount {
4+ $container = document . createElement ( "div" ) ;
5+ state : TodoCnt ;
56
6- const $container = document . createElement ( "div" ) ;
7- $target . appendChild ( $container ) ;
7+ constructor (
8+ private readonly $target : HTMLElement ,
9+ private readonly initialCount : TodoCnt
10+ ) {
11+ this . $target . appendChild ( this . $container ) ;
812
9- if ( initialCount . total ) {
10- this . state = initialCount ;
11- } else this . state = { total : 0 , done : 0 } ;
13+ if ( this . initialCount . total ) {
14+ this . state = this . initialCount ;
15+ } else this . state = { total : 0 , done : 0 } ;
1216
13- this . setState = ( nextState ) => {
17+ this . render ( ) ;
18+ }
19+
20+ setState ( nextState : TodoCnt ) {
1421 this . state = nextState ;
1522 this . render ( ) ;
1623 } ;
1724
18- this . render = ( ) => {
19- $container . textContent = `완료 ${ this . state . done } 개 / 총 ${ this . state . total } 개` ;
25+ render ( ) {
26+ this . $container . textContent = `완료 ${ this . state . done } 개 / 총 ${ this . state . total } 개` ;
2027 } ;
21-
22- this . render ( ) ;
2328}
You can’t perform that action at this time.
0 commit comments