Add support to unload and destroy a view.
edchat opened this issue · 7 comments
This support will be added to the Load controller.
There will be a new event called "app-unload-view" to handle unloading and destroying a view. Calls to use the new "app-unload-view" would look like this:
params.view = view;
this.app.emit("app-unload-view", params);
I would also like to add some config options to make it easy to avoid having too many views loaded. Perhaps support for the app or a view to have these options:
"alwaysAutoUnload": which if set to true means the view will automatically be unloaded and destroyed after afterDeactivate is called for the view.
"autoUnloadCount": which is set to a number which is used to determine how many views (per constraint) to leave loaded when transitioning in the application.
"neverAutoUnload": which if set to true means this view will never be automatically unloaded and destroyed no matter how many views are loaded.
Christophe suggested that in addition to support for unloading a view with the emit of the "app-unload-view" event we should add a function which can be called to unload the view as well to make it easier for an app to unload views.
Agreed with Christophe's suggestion.
Back in the dojox/mobile world, I've often found myself dynamically creating and reaping hierarchical structures - ie. only when transferring up the hierarchical view tree, as opposed from any deactivation.
I'd need to control this kind of logic programmatically, so a function would be helpful.
I will add an unloadView function was added to main.js, it will take these parameters:
(/Object/view, /function?/callback)
So a call would look like:
app.unloadView(/Object/view, /function?/callback);
shouldn't it be promised based instead of callback?
Yes, but I am going to have to convert all of the events that are using callbacks to be promise based, so I was thinking that I would do those all at the same time, if that is OK. I actually did not have any cases where the callback was needed, but thought it should be there just in case.
that's indeed fine doing it later.
The basic view unload support is in, the event is "dapp-unload-view", but it is currently only called for app.unloadApp(). I still need to add the auto unload options listed above, and the app.unloadView(...) support.