Ionic-framework: [Toast].dismissAll(), [Loading].dismissAll() make it static

Created on 29 Jul 2017  路  13Comments  路  Source: ionic-team/ionic-framework

ref: https://github.com/ionic-team/ionic/issues/12009
Ionic version:
[ ] 1.x
[ ] 2.x
[x] 3.x

I'm submitting a ...
[ ] bug report
[x] feature request

Expected behavior:

Loading.dismissAll();

Steps to reproduce:

this.loading.dismissAll();
// call again in another part of my code (like an helper class that centralize loading requests)
this.loading.dismissAll();

I wonder if we can make Loading.dismissAll() static?
I think that this error don't have to be occurred, because we call this function to do a global work over all the loading objects.

Most helpful comment

Oh ok.
So a valid solution to this issue would be to move the dismissAll to the ToastController
Then, lets say one page creates some toasts, another page can just inject toastCtrl: ToastController, and to this.toastCtrl.dismissAll() (because angular creates only one instance of the provider, it will know all of the current pointers.

So this is nice imo. @jgw96 will probably move this to the internal features repo, and it will be reviewed there.

All 13 comments

That error has to happen, because the popAll method is a promise.
This error can be fixed quickly, but currently there is a code freeze on master so I can't really make a PR for you.

For now, you can try try/catch with async, that might work, something like

(async() => { try { await this.loading.dismissAll() } catch(e) {} })()

hi @AmitMY
can we for example have a static array of objects in the Loading class or even on the LoadingController class
then the static dismissAll() method will just loop over that array and call the dismiss()for every Loading object separately

I don't really have a say in what goes in, but I guess I am wondering why do you need it to be static?
The dismiss is also a promise of it's own, so it won't solve this "race condition".

Do you have a use case to access the Loading class outside of an angular component/service?

sorry I wanted to talk about the Toast instead of Loading, but it may can be applied on the Loading too

I am wondering why do you need it to be static?

not because I need to call it from outside the angular, but because I found it more clean for the code, and more relative to the class rather than the object.
May I misunderstood something, but I see that Loading object represent a single loading element,
and the Toast object too represent a specific toast element, whereas the dismissAll() not related to a specific element but to the class itself including all the created elements of Loading or Toasts.
In the current case we have to check if the object not dismissed, if we didn't we may have an exception like this:

Runtime Error Uncaught (in promise): removeView was not found

Well, the dismissAll is not good practice. Whichever component created a loading should also dismiss it.
There are of course edge cases where this is harder to do, so dismissAll helps.

I still don't understand though, why static will help here, as it will do the same thing, really.

I do agree that moving the dismissAll to LoadingController makes more sense.

I still don't understand though, why static will help here, as it will do the same thing, really.

Let's say that we have a complicated case, where we may have more than one Toast, and in some point I want to clear all Toasts, I may not have a pointer to the all toasts objects.
or may having pointers of them make the code more complex, so I thought that making this method static will help us doing this function without the need to catch the variables themselves or one of them.
sorry my description may be not very clear, thank you for your hearing

Oh ok.
So a valid solution to this issue would be to move the dismissAll to the ToastController
Then, lets say one page creates some toasts, another page can just inject toastCtrl: ToastController, and to this.toastCtrl.dismissAll() (because angular creates only one instance of the provider, it will know all of the current pointers.

So this is nice imo. @jgw96 will probably move this to the internal features repo, and it will be reviewed there.

Hello everyone! Thanks for the feature request. I'm going to move this issue over to our internal list of feature requests for evaluation. We are continually prioritizing all requests that we receive with outstanding issues. We are extremely grateful for your feedback, but it may not always be our next priority. I'll copy the issue back to this repository when we have begun implementation. Thanks!

This issue was moved to ionic-team/ionic-feature-requests#285

thanks @jgw96 , but the link not working

internal list of feature requests

It is a private repository, to avoid noise. If this feature is to be implemented, this issue will be reopened

Okey

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GeorgeAnanthSoosai picture GeorgeAnanthSoosai  路  3Comments

MrBokeh picture MrBokeh  路  3Comments

vswarte picture vswarte  路  3Comments

alan-agius4 picture alan-agius4  路  3Comments

manucorporat picture manucorporat  路  3Comments