I recently read Jasper Woudenberg’s article about drag-and-drop and found it really insightful.
I had the idea to only check where elements are on the start of a drag action, which has the additional benefit of not having weird side-cases where drag actions impact the width of elements which impacts the drag action again, etc.
Since I would only measure the elements once, it would be possible to use
Browser.Dom.getElement (side note: would
measureElement be a better name than
This turned out to be problematic: It seems tasks are executed in a
requestAnimationFrame, and if I
Task.map2, the tasks are executed in order, but in individual animation frames.
There was a discussion about something similar previously:
Since it is unfortunately not possible to execute tasks in parallel, measuring e.g. 60 elements for drag-and-drop in a list takes 60 animation frames: in most cases 1 second.
In the same topic, Evan writes this:
My current feeling is that it might want an abstraction of its own, and the starting point there is to get a couple real examples where people feel this might be the best path.
So with the above description, I hoped to have contributed a real-world example, and I asynchronous
Task.map2 or similar would be the best solution.
Current alternatives include:
- Using a
If I understood this correctly,
Cmd.batchwould run both tasks in a single animation frame (am I correct?). However, this would mean a lot of additional complexity in my
Modeldatatype, which would be very hard to abstract out into a library or similar and feels like accidental complexity.
I realize I don’t really have a call-to-action. Maybe you had similar issues in the past? Do you agree with me? Did I miss something?