svelte-swipe
svelte-swipe copied to clipboard
[UPGRADE] Async Methods
Hello Again! I'm suggesting exporting async functions instead of the normal one because sometime we need to wait until the swipe is done and do the action
example having 2 items in my carousel and i want to go to second one after that reset the first item with new values (example of counting 5 reset to 0) but the issue is that I don't know when the swipe is done, using configs interval of delay is a little bit tricky because if the swipe was interrupted by the client
It should not do any action, else if he did swipe fast many times, and I'm using settimeout for the action, it will go crazy
What we have now
()=>{
SwipeComp.next();
setTimeout(()=> {
// do action
}, swipeconfig.delay);
}
what it will be after
()=>{
SwipeComp.next().then(()=>{
// do action if the swipe was not interrupted
});
}
or
async ()=>{
try {
await SwipeComp.next();
// do action if the swipe was not interrupted
}catch(rejected){
// rejected
}
}
Thanks ✨
Hello there! 👋
Thank you for raising this point. It sounds like transitioning to async functions could indeed enhance the synchronization of swipe actions with subsequent actions.
To better assist you with your specific use case, would you be able to provide a reproducible example (repl)? Having a clear demonstration of your carousel setup and the desired action behavior would greatly assist in understanding and addressing the situation accurately.
If you're able to create a minimal demo using platforms like CodeSandbox or JSFiddle, it would provide valuable context for me to work with. I'm here to help you tackle this, and having the example would allow me to offer a tailored solution.