@@ -4,43 +4,7 @@ import { render, component, h } from 'literaljs';
44
55import { Store } from './store' ;
66
7- const Row = component ( {
8- methods ( ) {
9- return {
10- rowClass ( ) {
11- const { item, selected } = this . props ;
12- return item . id === selected ? 'danger' : '' ;
13- }
14- } ;
15- } ,
16- render ( ) {
17- const { item, selectRow, deleteRow } = this . props ;
18- return (
19- < tr class = { this . rowClass ( ) } >
20- < td class = "col-md-1" > { item . id } </ td >
21- < td class = "col-md-4" >
22- < a events = { { click : ( ) => selectRow ( item . id ) } } >
23- { item . label }
24- </ a >
25- </ td >
26- < td class = "col-md-1" >
27- < a >
28- < span
29- class = "glyphicon glyphicon-remove"
30- aria-hidden = "true"
31- events = { { click : ( ) => deleteRow ( item . id ) } }
32- />
33- </ a >
34- </ td >
35- </ tr >
36- ) ;
37- }
38- } ) ;
39-
407const App = component ( {
41- state : {
42- store : new Store ( )
43- } ,
448 methods ( ) {
459 const { store } = this . getState ( ) ;
4610 return {
@@ -75,22 +39,11 @@ const App = component({
7539 swapRows ( ) {
7640 store . swapRows ( ) ;
7741 this . setState ( { store } ) ;
78- } ,
79- createRows ( ) {
80- return store . data . map ( item => (
81- < Row
82- props = { {
83- item,
84- selected : store . selected ,
85- deleteRow : this . delete ,
86- selectRow : this . select
87- } }
88- />
89- ) ) ;
9042 }
9143 } ;
9244 } ,
9345 render ( ) {
46+ const { store } = this . getState ( ) ;
9447 return (
9548 < div class = "container" >
9649 < div class = "jumbotron" >
@@ -165,7 +118,38 @@ const App = component({
165118 </ div >
166119 </ div >
167120 < table class = "table table-hover table-striped test-data" >
168- < tbody > { this . createRows ( ) } </ tbody >
121+ < tbody >
122+ { store . data . map ( item => (
123+ < tr
124+ class = {
125+ item . id === store . selected ? 'danger' : ''
126+ }
127+ >
128+ < td class = "col-md-1" > { item . id } </ td >
129+ < td class = "col-md-4" >
130+ < a
131+ events = { {
132+ click : ( ) => this . select ( item . id )
133+ } }
134+ >
135+ { item . label }
136+ </ a >
137+ </ td >
138+ < td class = "col-md-1" >
139+ < a >
140+ < span
141+ class = "glyphicon glyphicon-remove"
142+ aria-hidden = "true"
143+ events = { {
144+ click : ( ) =>
145+ this . delete ( item . id )
146+ } }
147+ />
148+ </ a >
149+ </ td >
150+ </ tr >
151+ ) ) }
152+ </ tbody >
169153 </ table >
170154 < span
171155 class = "preloadicon glyphicon glyphicon-remove"
@@ -176,4 +160,4 @@ const App = component({
176160 }
177161} ) ;
178162
179- render ( App , 'root' , { } ) ;
163+ render ( App , 'root' , { store : new Store ( ) } ) ;
0 commit comments