@@ -15,28 +15,27 @@ export default function App({ $target, initialState, initialCount }) {
1515 onSubmit : ( text ) => {
1616 const nextState = [ ...todoList . state , { text, isCompleted : false } ] ;
1717 todoList . setState ( nextState ) ;
18+ updateCount ( nextState ) ;
1819 setItem ( "todo" , JSON . stringify ( nextState ) ) ;
19-
20- const done = nextState . filter ( ( todo ) => todo . isCompleted ) . length ;
21- const count = { total : nextState . length , done } ;
22- todoCount . setState ( count ) ;
23- setItem ( "count" , JSON . stringify ( count ) ) ;
2420 } ,
2521 } ) ;
2622
2723 const todoList = new TodoList ( {
2824 $target,
2925 initialState,
30- updateCount : ( ) => {
31- const done = todoList . state . filter ( ( todo ) => todo . isCompleted ) . length ;
32- const nextState = { total : todoList . state . length , done } ;
33- todoCount . setState ( nextState ) ;
34- setItem ( "count" , JSON . stringify ( nextState ) ) ;
35- } ,
26+ updateCount : ( ) => updateCount ( todoList . state ) ,
3627 } ) ;
3728
3829 const todoCount = new TodoCount ( {
3930 $target,
4031 initialCount,
4132 } ) ;
33+
34+ // 카운트 업데이트
35+ const updateCount = ( todoList ) => {
36+ const done = todoList . filter ( ( todo ) => todo . isCompleted ) . length ;
37+ const nextState = { total : todoList . length , done } ;
38+ todoCount . setState ( nextState ) ;
39+ setItem ( "count" , JSON . stringify ( nextState ) ) ;
40+ } ;
4241}
0 commit comments