-
Notifications
You must be signed in to change notification settings - Fork 93
[RFC] Improve spawnDialog
or add a new function
#6731
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
Comments
You mean like extending a Promise? I do not like this 🙈 What are the requirements we have? So the use cases for the interface?
So a simple interface would be: function spawnDialog(component, props, dialogOptions)
// or
function spawnDialog(component, options: { props, options }) Maybe we can return an object? interface SpawnedDialog {
// to call exposed functions
dialog: VueInstance
// to get the result of the 'closed' event?
// maybe throw a `DialogUnmounted` error if unmounted instead of closed?
result: Promise<unknown> |
I'd also think about reusable dialog. Like we do tight now with the password confirmation or unified search - it is rendered once and then only opens closes. But it can also be a new function. Not only for dialogs. |
This doesn't hurt (at least without Vapor), works already and nice-to-have feature. Also for debugger.
You were the last person used it =D https://github.com/nextcloud-libraries/nextcloud-dialogs/blob/main/lib/dialogs.ts#L80
This doesn't look nice for prompts // With Promise
const wasConfirmed = await spawnDialog(Confirm)
const selectedConversation = await spawnDialog(ConversationSelector)
// With object
const wasConfirmed = await spawnDialog(Confirm).promise
const selectedConversation = await spawnDialog(ConversationSelector).promise As promise is needed in 99% cases, maybe make it controlled? const { vm, promise } = await spawnDialog(ConversationSelector, { controlled: true }) Or with different functions const selectedConversation = await promptDialog(ConversationSelector)
const vm = spawnDialog(ConversationSelector) |
In this case, for those two options, I would prefer having two functions. |
No, I was wrong, it hurts. With the current solution, the debugger doesn't work at all... |
Return It is a simple solution that covers both cases without making the API more complex.
It still does one job in my opinion - it mounts a one-time use prompt-like dialog. Different return values are for basic and advanced usage. And it's quite a common practice, for example, for composables with |
I thought a lot about this today, and I'd propose the following: 1. Do not
|
This comment has been minimized.
This comment has been minimized.
(and I wish we would have never done this and directly used standardized Extending promise is such a rabbit hole: spawnDialog()
.then(() => {})
.catch(() => {})
// this should work but in many implementations does not
.callSomeExtendedFunction() Personally I prefer simple return types like an object thats alway the same like above. const { promise, vm } = spawnDialog(...)
vm.callSomeExtendedFunction(...)
await promise
// I do not consider this really overhead
const { promise } = spawnDialog()
await promise
// or
await spawnDialog().promise But also this looks ok to me: // plain
await spawnDialog(component)
// with VM
const { promise, vm } = spawnDialog(component, { controlled: true }) |
You mean that we should have a hide function? This is basically the only use case why I added the possibility to unmount in the orginal |
I agree that global components do not matter - just register locally. |
Yes. I see we have the hide function, but do we need it? To hide a dialog from outside when it is open (so user cannot interact with anything outside). I don't know what could trigger It's also wierd for me, that we want to have |
Pinia should work out of the box at least with one Pinia instance. If there are many - you can provide it manually |
Then it's always overloaded only to support a rare case |
Nextcloud ecosystem -> there are many different apps.
Basically this comes from the JQuery dialogs migration where the api was like this. I would also be fine with deprecating this in general as this not really makes sense with the way our Vue dialogs work. |
Is something left @ShGKme ? |
Backport forward compatible version to v8 👀 |
Problem
In the current implementation
spawnDialog
is designed to create a one-time "prompt" dialog:unmount
it or call its public methodsBut at the same time, it isn't convenient as a prompt, requiring to pass callback instead of returning a promise.
Proposals
Additional problem
In the current API
props
argument is passed as dialog component props, but it includescontainer
andappContext
, which are not dialog props.We can mix it and only fix the implementation, or separate dialog's
props
andspawnDialog
'soptions
(breaking change).The text was updated successfully, but these errors were encountered: