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

Ability to inform miso of external DOM updates? #698

Open
liamoc opened this issue Apr 1, 2022 · 3 comments
Open

Ability to inform miso of external DOM updates? #698

liamoc opened this issue Apr 1, 2022 · 3 comments

Comments

@liamoc
Copy link

liamoc commented Apr 1, 2022

Is your feature request related to a problem? Please describe.
I am currently using Sortable.js (https://sortablejs.github.io/Sortable/) to make a nice easy drag-to-sort list of items. The way I make this cooperate with miso is to, in JS in the onEnd handler, call a custom event on the dragged item, and associating an action with that in the Miso view that updates the model by reordering the items. However, Sortable.js will mutate the DOM first, as the user drags stuff around, so Miso's view of the DOM will get out of sync with the real DOM here. Currently, my hack to make this work is to swap the DOM items back into their original order (bringing the model back in sync) before calling the event handler, but this means that, for a brief moment, the items revert back to their original order and then appear in the new order as required.

Describe the solution you'd like
Ideally, I'd like a way to tell Miso that certain DOM elements have been externally changed and to update its model accordingly, so I can bring the virtual DOM in line with the real DOM rather than the other way around.

Describe alternatives you've considered
I can't think of any alternative other than reimplementing the entire Sortable library in Miso (very difficult for all the features it has), or continuing with this undesirable swapping hack.

@dmjio
Copy link
Owner

dmjio commented Apr 7, 2022

Do you have a repo or a gist that I could repro the error here?

@liamoc
Copy link
Author

liamoc commented Apr 8, 2022

Not at the moment, but I can make one fairly easily I think. I'll post back when I do.

@liamoc
Copy link
Author

liamoc commented Apr 10, 2022

Hi @dmjio , I've added a minimal repro here. You'd need Sortable.js too of course:

https://gist.github.com/liamoc/97a92029233ad03f1ca9b97b4ff0e6c6

As you can see the list elements end up being displayed in a different order than they appear in the model.

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

No branches or pull requests

2 participants