PDA

View Full Version : Using the "stores" config in controllers instead of "requires"



tm8747a
28 Jan 2013, 11:40 AM
I'm looking at the docs and they say that


Ext.define("MyApp.controller.Foo", {
extend: "Ext.app.Controller",
stores: ['Users', 'Vehicles']
});

is the equivalent of


Ext.define("MyApp.controller.Foo", {
extend: "Ext.app.Controller",
requires: ['MyApp.store.Users', 'MyApp.store.Vehicles']
getUsersStore: function() {
return this.getView("Users");
},
getVehiclesStore: function() {
return this.getView("Vehicles");
}
});

From doing some testing though, they don't seem quite the same. Seems like when you use the "stores" config option, it also instantiates a store object whereas using requires doesn't. The way I tested this is creating a store with autoLoad: true. If I use the "stores" config option, an ajax request runs to load the store, whereas if I use "requires" no ajax runs, it only runs if I do Ext.create('MyApp.store.Users') or something along those lines that would instantiate an object. Am I missing something, or is that really the way it's meant to be and the docs just omitted that detail? I'm running version 4.1.1

mitchellsimoens
30 Jan 2013, 5:16 PM
That is correct, the stores property will create an instance where requires will just load the definition file and not create an instance. I can see how the docs are a little misleading and the author of the docs didn't think of that detail.

tm8747a
31 Jan 2013, 1:21 PM
That is correct, the stores property will create an instance where requires will just load the definition file and not create an instance. I can see how the docs are a little misleading and the author of the docs didn't think of that detail.
Thanks Mitchell. I added a comment to the docs to point out the difference.