Sharing and using common configuration values in Sencha Touch
When you’re developing an application that has multiple stores and AJAX calls – it would be a pain to have to search and replace all of the instances throughout your project. Instead, it’s common to use a shared Configuration class within Sencha Touch to store these values in a centralized location.
To do this in Sencha, we create a util folder under app and add the following to a class file named Config.js
The singleton configuration ensures that there is only ever a single instance in memory. In order to use this in your application, you can add it to your app’s requires config with a simple
requires: [ 'MyAwesomeApp.util.Config' ]
The only other tricky bit of code is in the constructor. The call initConfig is necessary to create the property accessors for your configuration properties. With this in place, Sencha will automatically create a function
that can be called where ever needed to provide one-stop shopping for your configuration needs. Note: This is also a handy place to store functions that are shared throughout your code. By convention we place shared functions in a separate file named Shared.js although there’s no reason they wouldn’t work as well in a single file.