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 Apr 18, 2018
1 parent 54a15f6 commit 20d357c
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" />
</div>
Expand Down Expand Up @@ -87,7 +89,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 @@ -98,10 +106,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,5 +1,5 @@
export default function (Component, Vue) {
return props => {
return (props, resolver) => {
const node = document.createElement('div')
document.body.appendChild(node)

Expand All @@ -17,8 +17,8 @@ export default function (Component, Vue) {
resolve(data)
vm.$destroy()
},
cancel: () => {
reject(new Error())
cancel: reason => {
reject(reason || new Error())
vm.$destroy()
}
}
Expand All @@ -27,6 +27,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 20d357c

Please sign in to comment.