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

Remove DOM manipulation and set list in onAdd and onRemove #78

Closed

Conversation

MartinMalinda
Copy link

Should close #77

Maybe I've removed too much stuff? I am not sure what are the checks for isRef? Isn't it safe to assume the list will always be a ref ? Should the lib work with non reactive arrays (why?)?


function getListFromEl(el: HTMLElement) {
const key = Object.keys(el).find(key => key.startsWith('Sortable'));
return key && (el as any)[key]?.__list;
Copy link
Author

Choose a reason for hiding this comment

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

This is a little bit ugly, but I need to have access to the original list to get the exact same object, not a clone. Cloning removes any getter and setter logic, thus kills reactivity.

Copy link
Author

Choose a reason for hiding this comment

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

But at least with this approach we rely on native Vue rerender instead of DOM manipulation 🤔

@Alfred-Skyblue
Copy link
Owner

If that's the case, we are changing the reference to the original array. Essentially, we are performing operations like adding, deleting, or moving elements within the original array. If we forcefully change the reference to the array, it could potentially lead to unnecessary issues, such as watch deep.

@MartinMalinda
Copy link
Author

MartinMalinda commented Dec 25, 2023

I'm very frequently doing list.value = [...newList.value] without issues. This triggers the setter on the ref and reactivity works just fine. I think what's important is not to break the child objects reactivity by cloning.

Besides, the code is already changing the reference to the original array on the most common operation, changing order:
https://github.com/Alfred-Skyblue/vue-draggable-plus/blob/main/src/useDraggable.ts#L175

@Alfred-Skyblue
Copy link
Owner

I am not sure what are the checks for isRef? Isn't it safe to assume the list will always be a ref ? Should the lib work with non reactive arrays (why?)?

Because ref is unpacked in the directive, isRef is used in useDraggable

But at least with this approach we rely on native Vue rerender instead of DOM manipulation 🤔

Manual manipulation of the DOM is necessary to trigger the animation effect.

@MartinMalinda
Copy link
Author

Thanks for the reply, I'll close this and proceed with forking.

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.

Dual list does not work with getter and setters
2 participants