You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Using a Redis DB where items are ordered in a list, to move an item you need to:
Delete the item in the list that is to be moved
Insert the item before or after the position in the list you want it to be in
This is much more performant than rewriting an array every single time a position changes.
However because onReorder only exposes the new state, you have to do a bunch of unnecessary computation to find the difference in the two arrays. It's also awkward to implement, especially considering how simple it would be to use a moved item index and find where in the new array its new index is.
Describe the solution you'd like
Either onReorder implements (newItems: any[], movedItem: number) => void or a new method is implemented (movedItem: number, {before: number} | {after: number}) or really any other method that at the very least exposes the moved item index.
Describe alternatives you've considered
Store the last moved item's using the Reorder.Item onDrag method. onDrag={()=>callback(value)}.
Find the index of the moved item's value const index = newOrder.indexOf(movedItem)
The following is specific to my needs of reordering in a Redis db, if anyone wants a solution for that specifically
Find the next/previous indexes const next = index + 1; const prev = index - 1
Determine whether we should move after or before an index next < newOrder.length ? after : prev >= 0 ? before : null
Update DB
Calculating the difference between the old array and the new array, to find the item that was moved. (I'm not going to figure out an example because the first alternative is much better.)
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Using a Redis DB where items are ordered in a list, to move an item you need to:
This is much more performant than rewriting an array every single time a position changes.
However because onReorder only exposes the new state, you have to do a bunch of unnecessary computation to find the difference in the two arrays. It's also awkward to implement, especially considering how simple it would be to use a moved item index and find where in the new array its new index is.
Describe the solution you'd like
Either onReorder implements
(newItems: any[], movedItem: number) => void
or a new method is implemented(movedItem: number, {before: number} | {after: number})
or really any other method that at the very least exposes the moved item index.Describe alternatives you've considered
onDrag={()=>callback(value)}
.const index = newOrder.indexOf(movedItem)
const next = index + 1; const prev = index - 1
next < newOrder.length ? after : prev >= 0 ? before : null
The text was updated successfully, but these errors were encountered: