Skip to content

Commit a980a81

Browse files
authored
Merge pull request #6759 from nextcloud-libraries/feat/spawnDialog--promise-only
feat(dialogs/spawnDialog)!: replace onClose callback with Promise
2 parents 5244eee + d7f8a08 commit a980a81

File tree

2 files changed

+6
-42
lines changed

2 files changed

+6
-42
lines changed

docs/functions/spawnDialog.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,18 @@ type SpawnDialogOptions = {
1919
container?: Element | string
2020
}
2121

22-
export function spawnDialog(
23-
dialog: Component,
24-
props?: object,
25-
onClose?: (...rest: unknown[]) => void,
26-
): void
27-
28-
export function spawnDialog(
29-
dialog: Component,
30-
props?: object,
31-
options?: SpawnDialogOptions,
32-
onClose?: (...rest: unknown[]) => void,
33-
): void
34-
3522
/**
3623
* Spawn a single-use Vue dialog instance to get the result when it is closed
3724
*
3825
* @param dialog - Dialog component to spawn
3926
* @param props - Props to pass to the dialog instance
40-
* @param optionsOrOnClose - Spawning options or a callback when the dialog is closed
41-
* @param onClose - Callback when the dialog is closed
27+
* @param options - Spawning options
4228
*/
4329
declare function spawnDialog(
4430
dialog: Component,
4531
props: object = {},
46-
optionsOrOnClose: SpawnDialogOptions | ((...rest: unknown[]) => void) = {},
47-
onClose: (...rest: unknown[]) => void = () => {},
48-
): void
32+
optionsOrOnClose: SpawnDialogOptions = {},
33+
): Promise<unknown>
4934
```
5035

5136
## Usage

src/functions/dialog/index.ts

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,20 @@ type SpawnDialogOptions = {
1313
container?: Element | string
1414
}
1515

16-
export function spawnDialog(
17-
dialog: Component,
18-
props?: object,
19-
onClose?: (...rest: unknown[]) => void,
20-
): Promise<unknown>
21-
22-
export function spawnDialog(
23-
dialog: Component,
24-
props?: object,
25-
options?: SpawnDialogOptions,
26-
onClose?: (...rest: unknown[]) => void,
27-
): Promise<unknown>
28-
2916
/**
3017
* Spawn a single-use Vue dialog instance to get the result when it is closed
3118
*
3219
* @param dialog - Dialog component to spawn
3320
* @param props - Props to pass to the dialog instance
34-
* @param optionsOrOnClose - Spawning options or a callback when the dialog is closed
35-
* @param onClose - Callback when the dialog is closed
21+
* @param options - Spawning options
3622
* @return Promise resolved with the `close` event payload
3723
*/
3824
export function spawnDialog(
3925
dialog: Component,
4026
props: object = {},
41-
optionsOrOnClose: SpawnDialogOptions | ((...rest: unknown[]) => void) = {},
42-
onClose?: (...rest: unknown[]) => void,
27+
options: SpawnDialogOptions = {},
4328
): Promise<unknown> {
44-
if (typeof optionsOrOnClose === 'function') {
45-
onClose = optionsOrOnClose
46-
optionsOrOnClose = {}
47-
}
48-
49-
let { container } = optionsOrOnClose
29+
let { container } = options
5030

5131
// For backwards compatibility try to use container from props
5232
if ('container' in props && typeof props.container === 'string') {
@@ -68,7 +48,6 @@ export function spawnDialog(
6848
onClose(...rest: unknown[]) {
6949
app.unmount()
7050
element.remove()
71-
onClose?.(...rest)
7251
resolve(rest.length > 1 ? rest : rest[0])
7352
},
7453
'onVue:unmounted'() {

0 commit comments

Comments
 (0)