Quasar: [Request] Return Promise instead of taking in callback input parameter

Created on 8 Oct 2017  路  5Comments  路  Source: quasarframework/quasar

I think the open/close methods in QModal should return a Promise instead of taking in a callback input parameter (or allow both for backwards compatibility).

This is in-line with the ES6 coding convention, and also since Quasar already requires a Promise implementation/polyfill to work. We can then take advantage of the benefits of using Promises, eg. Promise chaining, error propagation, etc.

There are probably also other methods that are also using the callback style instead of Promises that I'm not aware of.

Most helpful comment

There's two points to note here when using Promises:

  1. You can avoid the callback hell and indentation problems that regular callbacks generate.
  2. You can use async/await to further simplify code:
async showMe () {
   await this.$refs.modal.show()
   // ok, it's opened, do something
}

In any case, in v0.15 Modals/Popovers/Drawer/etc etc can now use a v-model which is way more elegant and fits perfectly with Vuex if you use it. Also, all of the ones mentioned have those show/hide() methods returning Promises now.

All 5 comments

This sounds like a good idea. Will see how this can be achieved. Thanks.

Yah, I think we should leave the callback method away.

Even if you use promises, you still need to provide a callback, and I don't see any use of .catch on toggle/open/close methods... They shouldn't "fail" to complete those tasks, and I don't think any developer may catch those scenarios. And if so, then a second error callback as parameter may be provided.
I suggest to stick with callback parameters, unless somebody states a really useful use case, or probably I'm missing some point here.

There's two points to note here when using Promises:

  1. You can avoid the callback hell and indentation problems that regular callbacks generate.
  2. You can use async/await to further simplify code:
async showMe () {
   await this.$refs.modal.show()
   // ok, it's opened, do something
}

In any case, in v0.15 Modals/Popovers/Drawer/etc etc can now use a v-model which is way more elegant and fits perfectly with Vuex if you use it. Also, all of the ones mentioned have those show/hide() methods returning Promises now.

Just a heads up, it seems that the documentation still suggests use of callbacks (no longer supported?), without any mention of promises. For example, in the modal docs:
https://quasar-framework.org/components/modal.html#Vue-Methods

Was this page helpful?
0 / 5 - 0 ratings

Related issues

victorborgaco picture victorborgaco  路  3Comments

jean-moldovan picture jean-moldovan  路  3Comments

fnicollier picture fnicollier  路  3Comments

adwidianjaya picture adwidianjaya  路  3Comments

nueko picture nueko  路  3Comments