File tree Expand file tree Collapse file tree 5 files changed +69
-24
lines changed Expand file tree Collapse file tree 5 files changed +69
-24
lines changed Original file line number Diff line number Diff line change @@ -171,6 +171,7 @@ main {
171
171
border : none;
172
172
-webkit-appearance : none;
173
173
appearance : none;
174
+ cursor : pointer;
174
175
}
175
176
176
177
.todo-list li .toggle {
Original file line number Diff line number Diff line change @@ -4,23 +4,47 @@ import TodoList from './TodoList.js';
4
4
5
5
export default function TodoApp ( $app ) {
6
6
this . state = {
7
- todoes : [ "hi I'm Tami" ] ,
8
- count : 0 ,
7
+ todoes : [
8
+ {
9
+ idx : 0 ,
10
+ content : 'hi EveryOne' ,
11
+ state : '' ,
12
+ edit : '' ,
13
+ } ,
14
+ {
15
+ idx : 2 ,
16
+ content : "I'm Tami" ,
17
+ state : '' ,
18
+ edit : '' ,
19
+ } ,
20
+ ] ,
9
21
} ;
10
22
11
23
this . setState = ( nextState ) => {
12
24
this . state = nextState ;
13
25
todoList . setState ( this . state . todoes ) ;
14
- todoCount . setState ( this . state . count ) ;
26
+ todoCount . setState ( this . state . todoes ) ;
15
27
} ;
16
28
17
29
new TodoInput ( {
18
30
$app,
19
31
onAdd : ( contents ) => {
20
- this . state . todoes . push ( contents ) ;
21
- this . setState ( this . state ) ;
32
+ const prevIdx = this . state . todoes [ this . state . todoes . length - 1 ] . idx ;
33
+
34
+ const newTodo = {
35
+ idx : prevIdx + 1 ,
36
+ content : contents ,
37
+ state : '' ,
38
+ edit : '' ,
39
+ } ;
40
+ this . state . todoes . push ( newTodo ) ;
41
+
42
+ this . setState ( {
43
+ ...this . state ,
44
+ } ) ;
22
45
} ,
23
46
} ) ;
47
+
24
48
const todoList = new TodoList ( {
25
49
$app,
26
50
initialState : this . state . todoes ,
Original file line number Diff line number Diff line change @@ -6,6 +6,11 @@ export default function TodoInput({ $app, onAdd }) {
6
6
this . $target . autofocus ;
7
7
$app . appendChild ( this . $target ) ;
8
8
9
+ this . setState = ( nextState ) => {
10
+ this . setState = nextState ;
11
+ this . render ( ) ;
12
+ } ;
13
+
9
14
this . $target . addEventListener ( 'keydown' , ( e ) => {
10
15
this . addTodoItem ( e ) ;
11
16
} ) ;
@@ -18,10 +23,6 @@ export default function TodoInput({ $app, onAdd }) {
18
23
$newTodoTarget . value = '' ;
19
24
}
20
25
} ;
21
- this . setState = ( nextState ) => {
22
- this . setState = nextState ;
23
- this . render ( ) ;
24
- } ;
25
26
26
27
this . render = ( ) => { } ;
27
28
}
Original file line number Diff line number Diff line change 1
- // export default TodoItem = ({ $app, content }) => {
2
- // this.state = content
3
- // this.$target = document.createElement('li')
1
+ export default TodoItem = ( { $app, content } ) => {
2
+ this . state = content ;
3
+ this . $target = document . createElement ( 'li' ) ;
4
+ $app . appendChild ( this . $target ) ;
5
+ this . setState = ( nextState ) => {
6
+ this . state = nextState ;
7
+ this . render ( ) ;
8
+ } ;
9
+ this . render = ( ) => {
10
+ const todoItemTemplate = `
11
+ <div class="view">
12
+ <input class="toggle" type="checkbox"/>
13
+ <label class="label">${ this . state } </label>
14
+ <button class="destroy"></button>
15
+ </div>
16
+ <input class="edit" value=${ this . state } />
17
+ ` ;
4
18
5
- // this.setState = (nextState) => {
6
- // this.state = nextState;
7
- // this.render()
8
- // }
9
- // this.render = () => {
10
- // const todoItemTemplate = `<li>${this.state</li>`
11
- // }
12
- // }
19
+ this . $target . innerHTML = todoItemTemplate ;
20
+ } ;
21
+ } ;
Original file line number Diff line number Diff line change @@ -12,18 +12,28 @@ export default function TodoList({ $app, initialState }) {
12
12
this . state = nextState ;
13
13
this . render ( ) ;
14
14
} ;
15
+ this . $target . addEventListener ( 'click' , ( e ) => { } ) ;
16
+
17
+ this . $target . addEventListener ( 'click' , ( e ) => {
18
+ console . log ( e . target . className ) ;
19
+ console . log ( e ) ;
20
+ const $node = e ;
21
+ const { nodeId } = $node . dataset ;
22
+ console . log ( 'nodeid' , nodeId ) ;
23
+ } ) ;
24
+ this . toggleTodo = ( e ) => { } ;
15
25
16
26
this . render = ( ) => {
17
27
const todoTemplate = `${ this . state
18
28
. map (
19
29
( todo , idx ) =>
20
- `<li>
30
+ `<li >
21
31
<div class="view">
22
- <input class="toggle" type="checkbox"/>
23
- <label class="label">${ todo } </label>
32
+ <input class="toggle" type="checkbox" data-node-id= ${ todo . idx } />
33
+ <label class="label">${ todo . content } </label>
24
34
<button class="destroy"></button>
25
35
</div>
26
- <input class="edit" value=${ todo } />
36
+ <input class="edit " value=${ todo . content } />
27
37
</li>`
28
38
)
29
39
. join ( '' ) } `;
You can’t perform that action at this time.
0 commit comments