The project that I am working on requires a sort of handshake procedure with the server before API calls can be made. I was intending to do this initialization in application#launch, but ran into a problem with stores where autoLoad is set to true. In this case, the stores are created and autoloaded before launch is called. I get the same behavior when I move the initialization code into a controller#init method as well. I can't seem to find a hook into the application lifecycle that allows me to execute my initialization code before the stores autoload themselves.
Is this not a use case that is supported?
At the moment, it seems like I only have three options:
- Override the store autoloading private method to call out to some singleton controlling the connection state, check the state, and initialize if necessary
- Override private methods within the application itself to give me the hook I need, or
- Do my initialization code outside of Sencha Touch, before the application begins to load.
Given that my intention is to turn this project into a user extension:
- I don't really want to have to subclass store. It seems prone to problems when upgrading Sencha Touch, it feels inelegant, and it's a big pain to have to remember to extend that class rather than Ext.Store when creating a new store (the Ext.Store stores will work in all cases except autoLoad, which has the potential to lead to subtle, hard-to-track-down bugs). It would be MUCH better if the users of the user extension could just configure it one place and have everything Just Work, rather than needing to subclass this special store over and over.
- I don't really want to have to override private methods in the application... That seems dangerous/unclean/inelegant/error-prone-during-version-upgrades. It has the advantage of being a bottlenecked, one-time change for users, but I myself would be reluctant to install a user extension with this requirement.
- I have a natural aversion to just throwing some globals onto the window, but it seems like the lesser of these evils.
Is there a better solution that I am missing? Is there a good reason why Sencha Touch is making it so hard for me to execute code before the stores load?