Skip to content

Commit c1f444d

Browse files
authored
Merge pull request #230 from SortableJS/infra-2
2 parents 43b721a + a658d04 commit c1f444d

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ temp
77
dist
88
# todo - get story book only when releasing.
99
storybook-static
10-
yarn.lock
10+
yarn.lock
11+
package-lock.json

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"arrowParens": "always",
3-
"semi": false
3+
"semi": true
44
}

src/react-sortable.tsx

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ export class ReactSortable<T extends ItemInterface> extends Component<
4949
this.ref = createRef<HTMLElement>();
5050

5151
// make all state false because we can't change sortable unless a mouse gesture is made.
52-
const newList = [...props.list];
53-
54-
newList.forEach((item: T) => {
52+
const newList = [...props.list].map((item) =>
5553
Object.assign(item, {
5654
chosen: false,
5755
selected: false,
58-
});
59-
})
56+
})
57+
);
6058

6159
props.setList(newList, this.sortable, store);
6260
invariant(
@@ -120,8 +118,8 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
120118
const dataid = dataIdAttr || "data-id";
121119
/* eslint-disable-next-line */
122120
return Children.map(children as ReactElement<any>[], (child, index) => {
123-
if (child === undefined) return undefined
124-
121+
if (child === undefined) return undefined;
122+
125123
const item = list[index] || {};
126124
const { className: prevClassName } = child.props;
127125

@@ -239,13 +237,12 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
239237
const customs = createCustoms(evt, otherList);
240238
removeNodes(customs);
241239

242-
const newList = handleStateAdd(customs, list, evt, clone)
243-
244-
newList.forEach((item) => {
240+
const newList = handleStateAdd(customs, list, evt, clone).map((item) =>
245241
Object.assign(item, {
246242
selected: false,
247-
});
248-
});
243+
})
244+
);
245+
249246
setList(newList, this.sortable, store);
250247
}
251248

@@ -296,11 +293,12 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
296293
}
297294

298295
// remove item.selected from list
299-
newList.forEach((item: T) => {
296+
newList = newList.map((item: T) =>
300297
Object.assign(item, {
301298
selected: false,
302-
});
303-
})
299+
})
300+
);
301+
304302
setList(newList, this.sortable, store);
305303
}
306304

@@ -324,25 +322,27 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
324322
onChoose(evt: SortableEvent): void {
325323
const { list, setList } = this.props;
326324
const newList = list.map((item, index) => {
325+
let newItem = item;
327326
if (index === evt.oldIndex) {
328-
Object.assign(item, {
327+
newItem = Object.assign(item, {
329328
chosen: true,
330329
});
331330
}
332-
return item;
331+
return newItem;
333332
});
334333
setList(newList, this.sortable, store);
335334
}
336335

337336
onUnchoose(evt: SortableEvent): void {
338337
const { list, setList } = this.props;
339338
const newList = list.map((item, index) => {
339+
let newItem = item;
340340
if (index === evt.oldIndex) {
341-
Object.assign(item, {
341+
newItem = Object.assign(newItem, {
342342
chosen: false,
343343
});
344344
}
345-
return item;
345+
return newItem;
346346
});
347347
setList(newList, this.sortable, store);
348348
}
@@ -354,12 +354,12 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
354354

355355
onSelect(evt: MultiDragEvent): void {
356356
const { list, setList } = this.props;
357-
const newList = [...list];
358-
newList.forEach((item) => {
357+
const newList = list.map((item) =>
359358
Object.assign(item, {
360-
chosen: false,
361-
});
362-
});
359+
selected: false,
360+
})
361+
);
362+
363363
evt.newIndicies.forEach((curr) => {
364364
const index = curr.index;
365365
if (index === -1) {
@@ -376,12 +376,11 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
376376

377377
onDeselect(evt: MultiDragEvent): void {
378378
const { list, setList } = this.props;
379-
const newList = [...list];
380-
newList.forEach((item) => {
379+
const newList = list.map((item) =>
381380
Object.assign(item, {
382-
chosen: false,
383-
});
384-
});
381+
selected: false,
382+
})
383+
);
385384
evt.newIndicies.forEach((curr) => {
386385
const index = curr.index;
387386
if (index === -1) return;

0 commit comments

Comments
 (0)