Skip to content

Commit

Permalink
Handle Set instances in deepEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
clauderic committed Jun 10, 2024
1 parent 7a9c040 commit 1483a9f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .changeset/bug-fixes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
'@dnd-kit/abstract': patch
'@dnd-kit/react': patch
'@dnd-kit/dom': patch
'@dnd-kit/state': patch
---

- `draggable`: Fixed a bug where the `element` was not properly being set on initialization
- `feedback`: Fixed a bug with optimistic re-ordering.
- `scroller`: Fixed a bug with auto-scrolling when target is position fixed
- `deepEqual`: Handle comparing `Set` instances
14 changes: 14 additions & 0 deletions packages/state/src/comparators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ export function deepEqual<T>(a: T, b: T) {
return true;
}

if (a instanceof Set && b instanceof Set) {
if (a.size !== b.size) {
return false;
}

for (const value of a) {
if (!b.has(value)) {
return false;
}
}

return true;
}

if (Array.isArray(a)) {
if (!Array.isArray(b) || a.length !== b.length) {
return false;
Expand Down

0 comments on commit 1483a9f

Please sign in to comment.