-
Notifications
You must be signed in to change notification settings - Fork 8
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
Make openModal
a promise that resolves when the modal closes
#17
Comments
I think this would be a good idea. This is likely a common scenario, and I don't see any drawbacks to having A few thoughts:
|
This will be added in #20 but with a slightly different API. Instead of providing the value to Reasons why:
you can try a repl here https://svelte.dev/repl/82473340d9de47e19e5a850e790042f8?version=3.49.0 |
I like this a lot! Thank you for working on this! |
Curious what the status of this issue is?! I saw a couple PRs were merged but wasn't sure if they made it into a proper release.. would love to leverage promises! |
Is your feature request related to a problem? Please describe.
Consider a confirmation dialog. A user gets a message "Are you sure?" and clicks yes or no. Currently you'd have to do this with callback props, they would have to exist on any modal component you'd want to wait for or have a return value for.
This works, but isn't optimal.
Describe the solution you'd like
Have the
openModal
function return a promise. This promise will resolve once the modal is closed.This could be done by extending the
StoredModal
interface with apromise
, and then onpop()
just resolve the promises of the modals you're popping.Then update
closeModal()
to accept a parameterreturnValue?: unknown
. That value will be handed to the eventualpop
function so it can be used to resolve the Promise. (To be helpful, add a generic toopenModal
so we know what to expect when it resolves)Now what a user could do is:
And in the modal itself, no extra callbacks or boilerplatey stuff would be required, just calling the close method would be sufficient:
Describe alternatives you've considered
Rather than returning the promise from
openModal
directly, it could also return an object with the promise, so in the future we could add more stuff to it. Either way is fine.I'd be very willing to make a PR for this. Just let me know if you'd be willing to accept such a PR.
The text was updated successfully, but these errors were encountered: