Skip to content
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

[Experimental branch] Allow the entity to have a new id #1448

Merged
merged 2 commits into from
Jul 16, 2024
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
5 changes: 5 additions & 0 deletions .changeset/rude-worms-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@dnd-kit/abstract": patch
---

Allow entities to receive a new id during the lifecycle of the entity
2 changes: 1 addition & 1 deletion packages/abstract/src/core/entities/entity/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Entity<
this.effects = () => [
() => {
// Re-run this effect whenever the `id` changes
const {id: _, manager} = this;
const {id, manager} = this;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between this code and the previous code?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weren't we discarding the value of id from this here? (by assigning to _)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is when the effect runs again, it will use whatever id is set in this, instead of the id that was received by the class constructor. That way if the id changes you're using the new id, not the initially set one.


if (id === previousId) {
return;
Expand Down