PDA

View Full Version : How to stop stores from autoloading with MVC



netslayer
11 Aug 2011, 3:18 PM
I have a store defined with autoLoad: false but when using the MVC application approach they seem to autoload during the application initiation. Any ideas on how to stop this?

Here is a code sample chopped down.



Ext.define('V.store.Properties', {
extend: 'Ext.data.Store',
model: 'V.model.Property',
autoLoad: false,
pageSize: 999,
proxy: {
type: 'ajax',
url: '...endPoint',
reader: {
type: 'json',
root: 'data',
totalProperty: 'totalCount',
idProperty: 'id'
}
}
});

Ext.define('V.controller.Properties', {
extend: 'Ext.app.Controller',

stores: [
'Properties'
],

views: [
'property.Grid'
],

models: [
'Property'
]
});

Ext.define('V.view.property.Grid', {
extend: 'Ext.grid.Panel',
store: 'Properties'
});

var v = Ext.create('Ext.app.Application', {
name: 'V',
appFolder: 'app',
controllers: [
'Properties'
],

launch: function() {
// more code here that creates an instance of V.view.property.Grid
}
});

slemmon
11 Aug 2011, 3:39 PM
Do you use the guaranteeRange method of your store at any point? I had set up a buffered store and used guaranteeRange and that performs a load action in the store. I might be way off. ;)

netslayer
11 Aug 2011, 4:03 PM
nope, not using that.

mberrie
12 Aug 2011, 3:55 AM
How good are you with the debugger? Set a breakpoint in Store#load() or by adding 'debugger' in the JS code.

Then trace back the call stack (the class/method that made the call to Store#load) and see where the method call comes from. That might help you understand what is going on.

mitchellsimoens
12 Aug 2011, 6:00 AM
Looking at the source for Ext.app.Application (which is where the stores you specify in a Controller get created), the getStore method doesn't do anything to auto load a Store.


getStore: function(name) {
var store = Ext.StoreManager.get(name);

if (!store) {
store = Ext.create(this.getModuleClassName(name, 'store'), {
storeId: name
});
}

return store;
}

If the Store is actually firing the load method, it would be because the StoreManager is falsely doing it but I personally haven't seen this behavior in my 4.x applications.

bt_bruno
15 Oct 2011, 10:17 AM
Looking at the source for Ext.app.Application (which is where the stores you specify in a Controller get created), the getStore method doesn't do anything to auto load a Store.
...

The getStore method instantiates the store by doing "store = Ext.create(...)". This fires the loading if autoLoad = true.

I've seen this same behavior occurring and what I'm doing is avoiding autoLoad and doing something like this into my views:


initComponent: function() {
// ...
this.callParent(arguments);
this.store.load();
}

This way I have store loaded once my view is instantiated, and not when the store is instantiated at application beginning.

Cheers!