I have an Ext/Sencha store proxy with a custom JSON reader. I noticed that the reader (hence, the proxy) is called way before it's used. The application launch process is like so:
- get geo location
- store it as global variable (namespaced)
- make AJAX call
- then create main view
Problem
I expect that the proxy isn't called before the main view (which adds a list which uses the store) is added. However, if the reader accesses the global geo variable set in the 2nd step very often it's null.
How can I work around that? The proxy must only be invoked once the geo location has been determined.
app.js code fragments
Ext.application({
models: ['Station'],
stores: ['Stations'],
views: ['Main'],
controllers: ['Application'],
launch: function () {
Ext.create('Ext.util.Geolocation', {
...
listeners: {
locationupdate: function (geo) {
// store lat/long as global variables
Ext.Ajax.request({
...
success: function (response) {
...
Ext.fly('appLoadingIndicator').destroy();
Ext.Viewport.add(Ext.create('APP.view.Main'));
}
...
}).updateLocation();
app/store/Stations.js
Ext.define('SunApp.store.Stations', {
extend: 'Ext.data.Store',
requires: ['SunApp.store.StationReader'],
config: {
autoLoad: true,
...
proxy: {
...
reader: {
type: 'stationReader'
}
}
}
});
app/store/StationReader.js
Ext.define('SunApp.store.StationReader', {
extend: 'Ext.data.reader.Json',
alias: 'reader.stationReader',
getResponseData: function (response) {
var data = this.callParent([response]);
return this.filter(data);
},
...
});