@@ -47,7 +47,7 @@ export class ReactSortable<T extends ItemInterface> extends Component<
47
47
this . ref = createRef < HTMLElement > ( ) ;
48
48
49
49
// make all state false because we can't change sortable unless a mouse gesture is made.
50
- const newList = [ ... props . list ] . map ( item => ( {
50
+ const newList = props . list . map ( item => ( {
51
51
...item ,
52
52
chosen : false ,
53
53
selected : false
@@ -293,15 +293,29 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
293
293
294
294
onChoose ( evt : SortableEvent ) {
295
295
const { list, setList } = this . props ;
296
- const newList = [ ...list ] ;
297
- newList [ evt . oldIndex ! ] . chosen = true ;
296
+ const newList = list . map ( ( item , index ) => {
297
+ if ( index === evt . oldIndex ) {
298
+ return {
299
+ ...item ,
300
+ chosen : true ,
301
+ }
302
+ }
303
+ return item ;
304
+ } ) ;
298
305
setList ( newList , this . sortable , store ) ;
299
306
}
300
307
301
308
onUnchoose ( evt : SortableEvent ) {
302
309
const { list, setList } = this . props ;
303
- const newList = [ ...list ] ;
304
- newList [ evt . oldIndex ! ] . chosen = false ;
310
+ const newList = list . map ( ( item , index ) => {
311
+ if ( index === evt . oldIndex ) {
312
+ return {
313
+ ...item ,
314
+ chosen : false ,
315
+ }
316
+ }
317
+ return item ;
318
+ } ) ;
305
319
setList ( newList , this . sortable , store ) ;
306
320
}
307
321
@@ -312,7 +326,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
312
326
313
327
onSelect ( evt : MultiDragEvent ) {
314
328
const { list, setList } = this . props ;
315
- const newList = [ ... list ] . map ( item => ( { ...item , selected : false } ) ) ;
329
+ const newList = list . map ( item => ( { ...item , selected : false } ) ) ;
316
330
evt . newIndicies . forEach ( curr => {
317
331
const index = curr . index ;
318
332
if ( index === - 1 ) {
@@ -329,7 +343,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
329
343
330
344
onDeselect ( evt : MultiDragEvent ) {
331
345
const { list, setList } = this . props ;
332
- const newList = [ ... list ] . map ( item => ( { ...item , selected : false } ) ) ;
346
+ const newList = list . map ( item => ( { ...item , selected : false } ) ) ;
333
347
evt . newIndicies . forEach ( curr => {
334
348
const index = curr . index ;
335
349
if ( index === - 1 ) return ;
0 commit comments