Skip to content

Conversation

@MathieuDerelle
Copy link

fixes #946

Comment on lines +138 to +154
updateValue($event: any): void {
// removing must be done before adding
// in order for the event `moved` to work properly
const dataForRemoving = $event.removed || $event.moved;
if (dataForRemoving) {
this.localValue.children.splice(dataForRemoving.oldIndex, 1);
}
const dataForAdding = $event.added || $event.moved;
if (dataForAdding) {
this.localValue.children.splice(
dataForAdding.newIndex,
0,
dataForAdding.element
);
}
Copy link
Author

Choose a reason for hiding this comment

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

the mutating error is fixed by the 2 other changes that create a shallow copy of children for localValue

but without this change, a strange bug appears :

Screen.Recording.2023-11-02.at.15.22.15.mov

on drag/drop, multiple updates occur :

  1. the child "test 2" gets updated with its now 4 children
  2. the parent "Plats cuisinés" gets updated with its now only 1 child "test 2" (but the value passed of "test 2" has only the 3 original children, not the now 4)

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.

Error: [vuex] do not mutate vuex store state outside mutation handlers.

1 participant