@@ -86,14 +86,25 @@ const Model = (() => {
86
86
$data . emit ( ) ;
87
87
} ;
88
88
89
+ const dispose = ( ) : void => {
90
+ const data = $data ( ) ;
91
+ for ( let i = 0 , l = data . length ; i < l ; i ++ ) {
92
+ data [ i ] . label . dispose ( ) ;
93
+ }
94
+ isSelected . dispose ( ) ;
95
+ } ;
96
+
89
97
const clear = ( ) : void => {
98
+ dispose ( ) ;
90
99
$data ( [ ] ) ;
91
100
} ;
92
101
93
102
const remove = ( id : number ) : void => {
94
103
const data = $data ( ) ;
95
104
const index = data . findIndex ( datum => datum . id === id ) ;
96
105
if ( index === - 1 ) return ;
106
+ const datum = data [ index ] ;
107
+ datum . label . dispose ( ) ;
97
108
data . splice ( index , 1 ) ;
98
109
$data . emit ( ) ;
99
110
} ;
@@ -102,7 +113,9 @@ const Model = (() => {
102
113
$selected ( id ) ;
103
114
} ;
104
115
105
- return { $data, $selected, run, runLots, runWith, add, update, swapRows, clear, remove, select } ;
116
+ const isSelected = useSelector ( $selected ) ;
117
+
118
+ return { $data, $selected, run, runLots, runWith, add, update, swapRows, dispose, clear, remove, select, isSelected } ;
106
119
107
120
} ) ( ) ;
108
121
@@ -114,7 +127,7 @@ const Button = ({ id, text, onClick }: { id: string | number, text: string, onCl
114
127
</ div >
115
128
) ;
116
129
117
- const RowDynamic = ( { id, label, className, onSelect, onRemove } : { id : FunctionMaybe < string | number > , label : FunctionMaybe < string > , className : FunctionMaybe < string > , onSelect : ObservableMaybe < ( ( event : MouseEvent ) => any ) > , onRemove : ObservableMaybe < ( ( event : MouseEvent ) => any ) > } ) : JSX . Element => (
130
+ const Row = template ( ( { id, label, className, onSelect, onRemove } : { id : FunctionMaybe < string | number > , label : FunctionMaybe < string > , className : FunctionMaybe < string > , onSelect : ObservableMaybe < ( ( event : MouseEvent ) => any ) > , onRemove : ObservableMaybe < ( ( event : MouseEvent ) => any ) > } ) : JSX . Element => (
118
131
< tr className = { className } >
119
132
< td class = "col-md-1" > { id } </ td >
120
133
< td class = "col-md-4" >
@@ -127,14 +140,11 @@ const RowDynamic = ({ id, label, className, onSelect, onRemove }: { id: Function
127
140
</ td >
128
141
< td class = "col-md-6" > </ td >
129
142
</ tr >
130
- ) ;
131
-
132
- const RowTemplate = template ( RowDynamic , { recycle : false } ) ;
143
+ ) ) ;
133
144
134
145
const App = ( ) : JSX . Element => {
135
146
136
- const { $data, $selected, run, runLots, add, update, clear, swapRows, select, remove} = Model ;
137
- const isSelected = useSelector ( $selected ) ;
147
+ const { $data, run, runLots, add, update, swapRows, clear, remove, select, isSelected} = Model ;
138
148
139
149
return (
140
150
< div class = "container" >
@@ -164,8 +174,7 @@ const App = (): JSX.Element => {
164
174
const onSelect = select . bind ( undefined , id ) ;
165
175
const onRemove = remove . bind ( undefined , id ) ;
166
176
const props = { id, label, className, onSelect, onRemove} ;
167
- return RowTemplate ( props ) ;
168
- // return RowDynamic ( props );
177
+ return Row ( props ) ;
169
178
} }
170
179
</ For >
171
180
</ tbody >
0 commit comments