11var  sf  =  require ( 'scarletsframe' ) ; 
2+ var  $  =  sf . dom ; 
23
34// Declare variable for the model 
45sf . model . for ( 'bench-mark' ,  function ( self ) { 
56    self . list  =  [ ] ; 
67    self . selected  =  - 1 ; 
7-     self . selectedRow  =  null ; 
88} ) ; 
99
1010// Declare functions that controlling the model 
@@ -26,6 +26,7 @@ sf.controller.run('bench-mark', function(self, root){
2626        for  ( var  i  =  0 ;  i  <  count ;  i ++ ) 
2727            data . push ( { 
2828                id : nextId ++ , 
29+                 status :'' , 
2930                label : adjectives [ _random ( adjectives . length ) ]  +  " "  +  colours [ _random ( colours . length ) ]  +  " "  +  nouns [ _random ( nouns . length ) ] 
3031            } ) ; 
3132
@@ -34,24 +35,27 @@ sf.controller.run('bench-mark', function(self, root){
3435
3536    self . unselect  =  function ( ) { 
3637        if ( self . selected  ===  - 1 )  return ; 
38+ 
39+         if ( self . list [ self . selected ]  !==  undefined ) { 
40+             self . list [ self . selected ] . status  =  '' ; 
41+             self . list . softRefresh ( self . selected ) ; 
42+         } 
43+ 
3744        self . selected  =  - 1 ; 
38-         
39-         if ( self . selectedRow  !==  undefined ) 
40-             self . selectedRow . className  =  "" ; 
4145    } 
4246
4347    // Handle button 
4448    self . b_run  =  function ( ) { 
4549        Measurer . start ( "run" ) ; 
4650        self . list  =  self . buildData ( ) ; 
47-         self . unselect ( ) ; 
51+         self . selected   =   - 1 ; 
4852        Measurer . stop ( ) ; 
4953    } 
5054
5155    self . b_runlots  =  function ( ) { 
5256        Measurer . start ( "runLots" ) ; 
5357        self . list  =  self . buildData ( 10000 ) ; 
54-         self . unselect ( ) ; 
58+         self . selected   =   - 1 ; 
5559        Measurer . stop ( ) ; 
5660    } 
5761
@@ -73,30 +77,42 @@ sf.controller.run('bench-mark', function(self, root){
7377    self . b_clear  =  function ( ) { 
7478        Measurer . start ( "clear" ) ; 
7579        self . list . splice ( 0 ) ; 
76-         self . unselect ( ) ; 
80+         self . selected   =   - 1 ; 
7781        Measurer . stop ( ) ; 
7882    } 
7983
8084    self . b_swaprows  =  function ( ) { 
8185        Measurer . start ( "swapRows" ) ; 
82-         if ( self . list . length  >  998 ) { 
86+ 
87+         if ( self . list . length  >  998 ) 
8388            self . list . swap ( 1 ,  998 ) ; 
84-          } 
89+ 
8590        Measurer . stop ( ) ; 
8691    } 
8792
8893    self . b_select  =  function ( el ) { 
8994        Measurer . start ( "select" ) ; 
9095        self . unselect ( ) ; 
91-         self . selectedRow  =  el . parentNode . parentNode ; 
92-         self . selected  =  sf . model . index ( self . selectedRow ) ; 
93-         self . selectedRow . className  =  "danger" ; 
96+ 
97+         var  rowIndex  =  $ . parent ( el ,  '[sf-bind-list]' ) ; 
98+         self . selected  =  rowIndex  =  sf . model . index ( rowIndex ) ; 
99+ 
100+         self . list [ rowIndex ] . status  =  'danger' ; 
101+         self . list . softRefresh ( rowIndex ) ; 
94102        Measurer . stop ( ) ; 
95103    } 
96104
97105    self . b_remove  =  function ( el ) { 
98106        Measurer . start ( "delete" ) ; 
99-         self . list . splice ( sf . model . index ( el . parentNode . parentNode ) ,  1 ) ; 
107+ 
108+         var  rowIndex  =  $ . parent ( el ,  '[sf-bind-list]' ) ; 
109+         rowIndex  =  sf . model . index ( rowIndex ) ; 
110+ 
111+         self . list . splice ( rowIndex ,  1 ) ; 
112+ 
113+         if ( rowIndex  ===  self . selected ) 
114+             self . selected  =  - 1 ; 
115+ 
100116        Measurer . stop ( ) ; 
101117    } 
102118} ) ; 
0 commit comments