Skip to content

Commit

Permalink
Allow dialog and action-sheet plugins to receive a resolver token
Browse files Browse the repository at this point in the history
  • Loading branch information
pdanpdan committed Jun 8, 2018
1 parent 075fe7e commit 66d6ca1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
16 changes: 12 additions & 4 deletions dev/components/global/dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
<q-btn label="Toggle ref" @click="toggle" />
<q-btn label="Toggle model" @click="toggle2" />
<q-btn label="Prompt" @click="adHoc" />
<q-btn label="Prompt - autoresolve in 3sec" @click="adHoc(3000, 'Autocompleted')" />
<q-btn label="Prompt - autoreject in 3sec" @click="adHoc(3000)" />
<q-btn label="Options" @click="adHoc2" />
<q-btn label="Confirm" @click="adHoc3" />
<q-btn label="Method" @click="asMethod" />
Expand Down Expand Up @@ -90,7 +92,13 @@ export default {
Promise.resolve(okFn()).then(() => this.$q.notify(`Ok ${this.name}, going with ${hero}`))
}
},
adHoc () {
adHoc (autoclose, autoResolve) {
const resolver = autoclose > 0
? new Promise((resolve, reject) => {
setTimeout(() => autoResolve ? resolve(autoResolve) : reject(new Error('Autoclosed')), autoclose)
})
: undefined
this.$q.dialog({
title: 'Prompt',
message: 'Modern HTML5 Single Page Application front-end framework on steroids.',
Expand All @@ -101,10 +109,10 @@ export default {
cancel: true,
// preventClose: true,
color: 'secondary'
}).then(data => {
}, resolver).then(data => {
console.log('>>>> OK, received:', data)
}).catch(() => {
console.log('>>>> Cancel')
}).catch(error => {
console.log('>>>> Cancel', String(error))
})
},
adHoc2 () {
Expand Down
15 changes: 12 additions & 3 deletions src/utils/modal-fn.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isSSR } from '../plugins/platform'

export default function (Component, Vue) {
return props => {
return (props, resolver) => {
return new Promise((resolve, reject) => {
if (isSSR) { return }

Expand All @@ -21,8 +21,8 @@ export default function (Component, Vue) {
resolve(data)
vm.$destroy()
},
cancel: () => {
reject(new Error())
cancel: reason => {
reject(reason || new Error())
vm.$destroy()
}
}
Expand All @@ -31,6 +31,15 @@ export default function (Component, Vue) {
this.$refs.modal.show()
}
})
if (resolver) {
resolver.then(data => {
resolve(data)
vm.$destroy()
}).catch(reason => {
reject(reason || new Error())
vm.$destroy()
})
}
})
}
}

0 comments on commit 66d6ca1

Please sign in to comment.