Skip to content

fix: preserve original objects #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 37 additions & 18 deletions src/react-sortable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ export class ReactSortable<T extends ItemInterface> extends Component<
this.ref = createRef<HTMLElement>();

// make all state false because we can't change sortable unless a mouse gesture is made.
const newList = props.list.map((item) => ({
...item,
chosen: false,
selected: false,
}));
const newList = [...props.list];

newList.forEach((item: T) => {
Object.assign(item, {
chosen: false,
selected: false,
});
})

props.setList(newList, this.sortable, store);
invariant(
Expand Down Expand Up @@ -235,10 +238,14 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
const otherList = [...store.dragging!.props.list];
const customs = createCustoms(evt, otherList);
removeNodes(customs);
const newList = handleStateAdd(customs, list, evt, clone).map((item) => ({
...item,
selected: false,
}));

const newList = handleStateAdd(customs, list, evt, clone)

newList.forEach((item) => {
Object.assign(item, {
selected: false,
});
});
setList(newList, this.sortable, store);
}

Expand Down Expand Up @@ -289,7 +296,11 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
}

// remove item.selected from list
newList = newList.map((item) => ({ ...item, selected: false }));
newList.forEach((item: T) => {
Object.assign(item, {
selected: false,
});
})
setList(newList, this.sortable, store);
}

Expand All @@ -314,10 +325,9 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
const { list, setList } = this.props;
const newList = list.map((item, index) => {
if (index === evt.oldIndex) {
return {
...item,
Object.assign(item, {
chosen: true,
};
});
}
return item;
});
Expand All @@ -328,10 +338,9 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
const { list, setList } = this.props;
const newList = list.map((item, index) => {
if (index === evt.oldIndex) {
return {
...item,
Object.assign(item, {
chosen: false,
};
});
}
return item;
});
Expand All @@ -345,7 +354,12 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl

onSelect(evt: MultiDragEvent): void {
const { list, setList } = this.props;
const newList = list.map((item) => ({ ...item, selected: false }));
const newList = [...list];
newList.forEach((item) => {
Object.assign(item, {
chosen: false,
});
});
evt.newIndicies.forEach((curr) => {
const index = curr.index;
if (index === -1) {
Expand All @@ -362,7 +376,12 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl

onDeselect(evt: MultiDragEvent): void {
const { list, setList } = this.props;
const newList = list.map((item) => ({ ...item, selected: false }));
const newList = [...list];
newList.forEach((item) => {
Object.assign(item, {
chosen: false,
});
});
evt.newIndicies.forEach((curr) => {
const index = curr.index;
if (index === -1) return;
Expand Down