Skip to content

Commit c0d0115

Browse files
committed
feat: api return promise, refactor unit test
1 parent 6984546 commit c0d0115

16 files changed

+258
-201
lines changed

dist/VueFinalModal.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/en/api.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ export default {
3131
- Arguments:
3232
- name: `String` - Name of the modal
3333
- params: `?: object` - Any data that you want to pass into the modal, checkout the guide [params](/guide/params).
34+
- Returns: Promise<Object> | Promise<Array>
3435

3536
<show-code text="Example">
3637

3738
<v-api-show class="py-4"></v-api-show>
3839

3940
```js
4041
this.$vfm.show('example', { userName: 'vue-final-modal' })
42+
.then(() => {
43+
// do something on modal opened
44+
})
4145
```
4246

4347
```html[Modal.vue]
@@ -67,6 +71,7 @@ this.$vfm.show('example', { userName: 'vue-final-modal' })
6771
- Type: `Function`
6872
- Arguments:
6973
- names: `String` - The names to hide
74+
- Returns: Promise<Object> | Promise<Array>
7075

7176
<show-code text="Example">
7277

@@ -83,7 +88,9 @@ this.$vfm.show('example', { userName: 'vue-final-modal' })
8388
show2: true
8489
}),
8590
mounted() {
86-
this.$vfm.hide('example', 'example2')
91+
this.$vfm.hide('example', 'example2').then(() => {
92+
// do something on modal closed
93+
})
8794
}
8895
}
8996
</script>
@@ -93,18 +100,33 @@ this.$vfm.show('example', { userName: 'vue-final-modal' })
93100

94101
### `hideAll()`
95102

103+
- Returns: Promise<Object> | Promise<Array>
104+
96105
hide all modals.
97106

107+
```js
108+
this.$vfm.hideAll().then(() => {
109+
// do something on all modals closed
110+
})
111+
```
112+
98113
### `toggle(name, show, params)`
99114

100115
- Type: `Function`
101116
- Arguments:
102117
- name: [`String` | `Array`] - The names of the modal
103118
- show: `?: Boolean` - Show modal or not
104119
- params: `?: object` - Any data that you want to pass into the modal, checkout the guide [params](/guide/params).
120+
- Returns: Promise<Object> | Promise<Array>
105121

106122
toggle modals by name.
107123

124+
```js
125+
this.$vfm.toggle('myModal').then(() => {
126+
// do something on modals opened or closed, it depends on params `show` is true or false
127+
})
128+
```
129+
108130
### `get([names])`
109131

110132
- Type: `Function`

docs/content/en/dynamic-modal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ To show dynamic modal you can use the API `$vfm.show` function.
4242
- Arguments:
4343
- dynamicModalOptions: `Object`
4444
- params: same as [API $vfm.show](/api#showname-params)
45+
- Returns: Promise<Object> | Promise<Array>
4546

4647
```ts
4748
type dynamicModalOptions = {

docs/content/zh-Hant/api.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ export default {
3131
- 參數:
3232
- name: `String` - 指定 modal 的名字。
3333
- params: `?: object` - Any data that you want to pass into the modal, checkout the guide [params](/zh-Hant/guide/params).
34+
- 回傳: Promise<Object> | Promise<Array>
3435

3536
<show-code text="Example">
3637

3738
<v-api-show class="py-4"></v-api-show>
3839

3940
```js
4041
this.$vfm.show('example', { userName: 'vue-final-modal' })
42+
.then(() => {
43+
// 當 modal 開啟後,做一些事
44+
})
4145
```
4246

4347
```html[Modal.vue]
@@ -67,6 +71,7 @@ this.$vfm.show('example', { userName: 'vue-final-modal' })
6771
- 型別: `Function`
6872
- 參數:
6973
- names: `String` - 指定要隱藏 modal 名稱。
74+
- 回傳: Promise<Object> | Promise<Array>
7075

7176
<show-code text="Example">
7277

@@ -83,7 +88,9 @@ this.$vfm.show('example', { userName: 'vue-final-modal' })
8388
show2: true
8489
}),
8590
mounted() {
86-
this.$vfm.hide('example', 'example2')
91+
this.$vfm.hide('example', 'example2').then(() => {
92+
// 當 modal 關閉後,做一些事
93+
})
8794
}
8895
}
8996
</script>
@@ -93,18 +100,33 @@ this.$vfm.show('example', { userName: 'vue-final-modal' })
93100

94101
### `hideAll()`
95102

103+
- 回傳: Promise<Object> | Promise<Array>
104+
96105
關閉所有的 modal。
97106

107+
```js
108+
this.$vfm.hideAll().then(() => {
109+
// 當所有 modal 關閉後,做一些事
110+
})
111+
```
112+
98113
### `toggle(name, show, params)`
99114

100115
- 型別: `Function`
101116
- 參數:
102117
- name: [`String` | `Array`] - modal 的名稱。
103118
- show: `?: Boolean` - 打開或隱藏這個 modal。
104119
- params: `?: object` - 任何你想要傳入 modal 的資料,詳閱 [參數(params)](/zh-Hant/guide/params)
120+
- 回傳: Promise<Object> | Promise<Array>
105121

106122
根據名字(name)切換 modals 的狀態。
107123

124+
```js
125+
this.$vfm.toggle('myModal').then(() => {
126+
// 當多個 modal 被開啟或被關閉時,做一些事,開啟或關閉取決於 show 參數給的是 true 或 false
127+
})
128+
```
129+
108130
### `get([names])`
109131

110132
- 型別: `Function`

docs/content/zh-Hant/dynamic-modal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ features:
4242
- 參數:
4343
- dynamicModalOptions: `Object`
4444
- params: 與 [API $vfm.show](/zh-Hant/api#showname-params) 相同
45+
- 回傳: Promise<Object> | Promise<Array>
4546

4647
```ts
4748
type dynamicModalOptions = {

example/src/components/basic/VDynamicModal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<vue-final-modal v-bind="$attrs" classes="modal-container" content-class="modal-content">
3-
<button class="modal__close" @click="$attrs['update:modalValue']">
3+
<button class="modal__close" @click="$attrs['onUpdate:modelValue'](false)">
44
<mdi-close></mdi-close>
55
</button>
66
<span class="modal__title">Hello, vue-final-modal</span>

example/src/components/hoc/VModal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default {
2525
emits: ['confirm', 'cancel'],
2626
methods: {
2727
close() {
28-
$attrs['update:modalValue']()
28+
this.$attrs['onUpdate:modelValue'](false)
2929
}
3030
}
3131
}

0 commit comments

Comments
 (0)