View Full Version : How to know when a store is created?

8 Jun 2012, 8:09 AM

I am creating a store without data in it and later supply both data and model. But there seems to be a race condition between creating the store and setting the data. If I set the data and model right after in the store doesnt seem to understand it, but if I do a setTimeout 3000 in which I set the same data and model it works.

Is there some kind of event I could listen to, in order to know when the store is done creating itself?

This is the working code, to make it break. just remove the setTimeout and let the code run.

var myStore = Ext.create('Ext.data.Store', {
autoLoad: true,
autoSave: true,
fields: [],
proxy: {
type: 'memory',
reader: {
type: 'json',
writer: {
type: 'json',
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
{name: 'age', type: 'int'},
{name: 'type', type: 'string'}

name: "foo",
age: 33,
type: "human"
}, {
name: "bar",
age: 33,
type: "human"
}, {
name: "affe",
age: 1,
type: "apa"
} ]);


//lets see if the store is populated

}, 3000);


8 Jun 2012, 8:14 AM
Actually that code works in the console without setTimeout but if you write the same console.log statement again manually (that is a little later) the array is empty.

Something in the lifecycle empties the store.data.items array!

EDIT: Seems Autoload=true was a major Fail. It also clears the store and makes no sense in general. :)

Anyone have a clue?