PDA

View Full Version : How does Ext Store handle overlapping loads?



Wedgie
5 Dec 2011, 10:56 AM
Here is my use case: As my user browses a master/detail result set I want him/her to be able to load and view the summary information quickly, while in the background I load the detail information. I don't want them to have to wait for the details to be loaded before they go to the next record in the result set.

This scenario will create overlapping loads, in the sense that the details for one record may not have been fully loaded before the next is selected.

Does the Ext Store component have a way of handling this, or does it simply use the last received data? If it uses the last received data then it seems that I can't guarantee that the details will actually match the currently selected summary record. In which case I'm open to suggestions as to how to solve this problem.

bt_bruno
5 Dec 2011, 11:59 AM
Yes you're right, you can't guarantee that out of the box. But I can't understand the use of a store for the details view. Could you maybe explain with some code how is your master/details structure looks like?

Because maybe we can use regular Ext.Ajax requests, and as a new request is made, we can abort the previous one. Or maybe we can save the record details within the store, so we can guarantee that the exactly record that requested details information, will actually receive this information.

Anyway, gets complicated without code sample.

Wedgie
5 Dec 2011, 1:02 PM
Thanks Bruno. I'm trying to do this in Ext Designer so I don't have a small code sample, but the scenario is I think fairly common and hopefully I can make it clear without dummying up code.

Basically I am writing a classic "order form" type application where the user fills in summary information for the order and then creates a number of detail items for each thing being ordered.

The summary information is being displayed in an Ext.form.Panel and the details are displayed in an Ext.grid.Panel, each with their own Store. This results in two requests, one (the summary) being very short and the other (the details) quite long. I don't want the user to have to wait for the loading of the detail items if they only want to look at the summary information.

It would be nice if each load of an Ext Store set an identifier, possibly just a simple time stamp, such that the latest load request can be detected and not overwritten by the latest arriving data, which of course is not guaranteed to match the latest request. But as you say, this feature isn't there. So it's looking like I will need to do my own request and response marshaling along the lines you were thinking.

bt_bruno
5 Dec 2011, 1:35 PM
I think the best would be abort old request, so we save some processing and stuff. We could make your store local, and fill it with a regular Ext.Ajax request. Maybe this snippet could help you out:
if(this.activeRequest) {
Ext.Ajax.abort(this.activeRequest);
}

this.activeRequest = Ext.Ajax.request({
url: 'order/details/' + id,
scope: this,
success: function(response) {
response = Ext.decode(response.responseText);
store.loadData(response);
delete this.activeRequest;
}
});

Maybe there's other solutions, but I think something like this will work.

Wedgie
5 Dec 2011, 2:22 PM
Thanks Bruno
I wouldn't have thought of deleting the Ext.Ajax.request object. I would have been concerned that it would not be cleanly handled and would lead to broken references somewhere in the Ext library. But if you think it is safe to do, then I'll give it a go.

bt_bruno
5 Dec 2011, 2:46 PM
The problem is, once you tell the datastore to load, there's nothing you could do to prevent grid of being populated. You can't do post-processing and check if the data loaded is really from the record that you wanted. The data is already loaded and displayed into the grid.

Only if you override onProxyLoad method, but things start to get messy.

Wedgie
5 Dec 2011, 3:26 PM
Yes, I agree Bruno. My approach was going to be to use an Ext.Ajax.request and a Store with a memory proxy and check that the received data was what I wanted before saving it to the Store, but if I can just blow away the existing Ext.Ajax.request without ill effect then that is a better solution as it will avoid the unnecessary load of the data from the server.

tobiu
5 Dec 2011, 3:33 PM
if you want to globally abort all ajax requests as soon as a new one pops up, also take a look at:
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Ajax-property-autoAbort

Wedgie
5 Dec 2011, 3:57 PM
Thanks Tobias, that looks like it might be handy under some circumstances, but your link led me to this one http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Ajax-method-abort (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.Ajax-method-abort) which looks like the approved method of aborting a specific pending request.

Now it would be kind of cool if the Store had something like this already built in.