-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Swappable:swap cancel async #603
Comments
To achieve asynchronous event handling with the swappable:swap event in the Draggable library, you need to handle the cancellation or continuation of the swap in a way that integrates with your asynchronous logic. The e.cancel() method only works synchronously, so you need to find a way to defer the decision to cancel the event until your asynchronous code completes. Here's how you can approach this problem by using a combination of requestAnimationFrame and a custom flag to handle the swap after the asynchronous operation completes: const containers = document.querySelectorAll('#container'); if (containers.length === 0) { const swappable = new Draggable.Swappable(containers, { let shouldCancelSwap = false; swappable.on('swappable:start', (e) => { swappable.on('swappable:swap', async (e) => {
}); // Optional: Handle the end of the swappable event to revert if necessary |
Is it possible to cancel or delay the swappable swap event?
I'd like to implement swapping, doing an ajax call, depending on the result, success -> continue with swapped, failure, revert the swapping or rather not let it continue. For now event.cancel(); only seems to work with a synchronous call.
The text was updated successfully, but these errors were encountered: