@@ -22,24 +22,24 @@ export default class TodoList {
2222 const target = e . target as HTMLLIElement ;
2323 const $li = target . closest ( "li" ) ;
2424
25- if ( $li ) {
26- const newState = [ ...this . state ] ;
27- if ( typeof $li . dataset . index !== "string" ) return ;
28- const index = + $li . dataset . index ;
25+ if ( ! $li ) return ;
2926
30- if ( target . className === "deleteBtn" ) {
31- newState . splice ( index , 1 ) ;
32- this . setState ( newState ) ;
33- } else if ( target . className . includes ( "todoList" ) ) {
34- const isCompleted = target . className . includes ( "completed" ) ;
35- if ( isCompleted ) target . classList . remove ( "completed" ) ;
36- else target . classList . add ( "completed" ) ;
37- newState [ index ] = {
38- ...newState [ index ] ,
39- isCompleted : ! isCompleted ,
40- } ;
41- this . setState ( newState ) ;
42- }
27+ const newState = [ ...this . state ] ;
28+ if ( typeof $li . dataset . index !== "string" ) return ;
29+ const index = + $li . dataset . index ;
30+
31+ if ( target . className === "deleteBtn" ) {
32+ newState . splice ( index , 1 ) ;
33+ this . setState ( newState ) ;
34+ } else if ( target . className . includes ( "todoList" ) ) {
35+ const isCompleted = target . className . includes ( "completed" ) ;
36+ if ( isCompleted ) target . classList . remove ( "completed" ) ;
37+ else target . classList . add ( "completed" ) ;
38+ newState [ index ] = {
39+ ...newState [ index ] ,
40+ isCompleted : ! isCompleted ,
41+ } ;
42+ this . setState ( newState ) ;
4343 }
4444 } ) ;
4545 }
0 commit comments