PDA

View Full Version : Store add event not firing when records added during load



joku
14 May 2008, 6:29 AM
Ext.data.Store: (v2.02)
The add event does not fire when records are being added after a call to Store.load().

Is this by design or is this a bug?

mjlecomte
14 May 2008, 6:33 AM
does the datachanged event fire?

Animal
14 May 2008, 6:36 AM
Is the loadexception event firing?

joku
14 May 2008, 6:41 AM
does the datachanged event fire?
Yes.

Is the loadexception event firing?
No.

And looking at the source code for Store, I noticed that the loadRecords function(callback from the reader to add records to the store) doesn't fire the add event...



// private
// Called as a callback by the Reader during a load operation.
loadRecords : function(o, options, success){
if(!o || success === false){
if(success !== false){
this.fireEvent("load", this, [], options);
}
if(options.callback){
options.callback.call(options.scope || this, [], options, false);
}
return;
}
var r = o.records, t = o.totalRecords || r.length;
if(!options || options.add !== true){
if(this.pruneModifiedRecords){
this.modified = [];
}
for(var i = 0, len = r.length; i < len; i++){
r[i].join(this);
}
if(this.snapshot){
this.data = this.snapshot;
delete this.snapshot;
}
this.data.clear();
this.data.addAll(r); //shouldn't the add event fire around here? Ext.util.MixedCollection does fire it's add event here
this.totalLength = t;
this.applySort();
this.fireEvent("datachanged", this);
}else{
this.totalLength = Math.max(t, this.data.length+r.length);
this.add(r);
}
this.fireEvent("load", this, r, options);
if(options.callback){
options.callback.call(options.scope || this, r, options, true);
}
},

Animal
14 May 2008, 8:05 AM
It fires datachanged.

Add is for individual additions.

loadData loads a whole batch of Records, so datachanged is more appropriate.

joku
14 May 2008, 8:34 AM
I have enough event handlers from the Store to do what I need to do, so it's not a big deal to me, I just wasn't sure if it was by design or not.

Also, the add event does return an array of records... and in my opinion anytime records are "added" to the store, the add event should probably be fired.

Thanks again for the speedy replies! :)

devnull
14 May 2008, 10:24 AM
a load may be replacing records in addition to or instead of adding records ;)