Manual dispatch in DragDropActions#drop()
acdlite opened this issue · comments
I noticed you're manually calling the dispatcher in DragDropActions#drop()
. https://github.com/gaearon/dnd-core/blob/master/modules/actions/DragDropActions.js#L90
Couldn't you instead dispatch all the dropResults at once? Or, if you need to do each one at a time, call a separate action instead of the raw dispatch method?
So instead of this
targetHandles.forEach((targetHandle, index) => {
...
this.dispatch(dropActionId, { dropResult });
});
you could do this
const dropResults = targetHandles.map((targetHandle, index) => {
...
return { dropResult };
});
return { dropResults };
or this
targetHandles.forEach((targetHandle, index) => {
...
this.dropSingle(dropResult);
});
// elsewhere in DragDropActions class
dropSingle(dropResult) {
return { dropResult };
}
If neither of these are options, I'd be curious to know why so I can address in Flummox.
Btw I'd be happy to submit a PR if you like.
I want the current drop result to be available in Store on each iteration. When I make that target.drop
call in the cycle, it might read from the Store.
I'm not super happy about it. While your second approach could work, I think the problem is me being lazy.
The correct approach would be to let context
be aware of the “ephemeral” drop target value so when we call target.drop(context)
, context.getDropResult()
inside it would return the work-in-progress result instead of reading it from the Store. After all such cases are the reason I hid direct Store access behind this context
proxy from user code.
When the loop is finished, we will dispatch exactly one drop
action. This sounds more solid.
I'm closing because we're going to drop Flummox anyway.