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

Conversation

lfades
Copy link

@lfades lfades commented Jul 3, 2024

When the id of the entity is updated from a component I noted that the element wasn't draggable anymore, as it if were not being detected. The reason was that the new id was not being compared in the id effect at Entity.

What I did was to change the effect to read the id from this rather than using the id received by the constructor. This makes sense because the new id is set to the class in the hooks:

useOnValueChange(id, () => (droppable.id = id));

With this change it should be straightforward to add a "Clone" example to the stories. I can do that too if you're interested.

Copy link

changeset-bot bot commented Jul 3, 2024

🦋 Changeset detected

Latest commit: 885caaa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@dnd-kit/abstract Patch
@dnd-kit/collision Patch
@dnd-kit/dom Patch
@dnd-kit/helpers Patch
@dnd-kit/react Patch
@dnd-kit/geometry Patch
@dnd-kit/state Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -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.

@clauderic clauderic merged commit 96f28ef into clauderic:experimental Jul 16, 2024
@github-actions github-actions bot mentioned this pull request Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants