Skip to content

fix: object-assign errors #230

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 2 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ temp
dist
# todo - get story book only when releasing.
storybook-static
yarn.lock
yarn.lock
package-lock.json
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"arrowParens": "always",
"semi": false
"semi": true
}
57 changes: 28 additions & 29 deletions src/react-sortable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ 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];

newList.forEach((item: T) => {
const newList = [...props.list].map((item) =>
Object.assign(item, {
chosen: false,
selected: false,
});
})
})
);

props.setList(newList, this.sortable, store);
invariant(
Expand Down Expand Up @@ -120,8 +118,8 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
const dataid = dataIdAttr || "data-id";
/* eslint-disable-next-line */
return Children.map(children as ReactElement<any>[], (child, index) => {
if (child === undefined) return undefined
if (child === undefined) return undefined;

const item = list[index] || {};
const { className: prevClassName } = child.props;

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

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

newList.forEach((item) => {
const newList = handleStateAdd(customs, list, evt, clone).map((item) =>
Object.assign(item, {
selected: false,
});
});
})
);

setList(newList, this.sortable, store);
}

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

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

setList(newList, this.sortable, store);
}

Expand All @@ -324,25 +322,27 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
onChoose(evt: SortableEvent): void {
const { list, setList } = this.props;
const newList = list.map((item, index) => {
let newItem = item;
if (index === evt.oldIndex) {
Object.assign(item, {
newItem = Object.assign(item, {
chosen: true,
});
}
return item;
return newItem;
});
setList(newList, this.sortable, store);
}

onUnchoose(evt: SortableEvent): void {
const { list, setList } = this.props;
const newList = list.map((item, index) => {
let newItem = item;
if (index === evt.oldIndex) {
Object.assign(item, {
newItem = Object.assign(newItem, {
chosen: false,
});
}
return item;
return newItem;
});
setList(newList, this.sortable, store);
}
Expand All @@ -354,12 +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];
newList.forEach((item) => {
const newList = list.map((item) =>
Object.assign(item, {
chosen: false,
});
});
selected: false,
})
);

evt.newIndicies.forEach((curr) => {
const index = curr.index;
if (index === -1) {
Expand All @@ -376,12 +376,11 @@ 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];
newList.forEach((item) => {
const newList = list.map((item) =>
Object.assign(item, {
chosen: false,
});
});
selected: false,
})
);
evt.newIndicies.forEach((curr) => {
const index = curr.index;
if (index === -1) return;
Expand Down