View Full Version : Help with choosing store and proxy for big application

19 Feb 2011, 3:43 AM
I´m build an application in Ext4 and I would be grateful if you could help me to choose the right components.

My app consists of a data model with about 10 fields. The datastore is going to have a normal load with around 100 records but at some rare cases up 2 000 records.

Through the application the user are going through different views containing dataview, gridpanel, custom components etc. I need all the data set to be loaded in the datastore to make different client decisions. For best UI performance I want the data to be viewed at about 100 items per page using a paging toolbar.

My questions is what type of store and proxy should I choose for my application? I want all the data in the store (Memoryproxy) but how do I use it with HttpProxy for saving to the server in json format? Do I have to make a custom proxy? And how do I make the datastore to use paging for local data?

And last, how should I sync back to the server? As I understand it there are three different types of writing?
a) Write at every record change. (That doesn't seem optimal because of the many operations the user are going to make, some rare cases around thousands of ajax calls).
b) Write to server at date interval?
c) Write to server at the end of the session? (I don't like the idea of the massive insert/update there going to be and how about the form post limitations? At most about 2 000 record of each 10 fields. And also it would be great if the user doesn't loose all data if the connection goes down.

I think I´m going with option b), what are your suggestions? Is there any built in functionality I can use if I for example want to change a record field “quantity” from 1 to 2 for all records, without going through a massive 2 000 json parameter call to the server?

19 Feb 2011, 7:32 AM
As a disclaimer, I'm not yet an experienced ExtJS developer, but since your question looks to me more like a question about architecture than about Ext itself and I do have several years of experience in building enterprise app architectures in .NET, here's how I see things:

A model with 10 fields, average load of 100 items / occasionally > 2,000 items is not exactly huge and I don't think it's something a rest/json store couldn't handle (provided you don't have fields containing entire novels, of course).

So there's no reason for not using a store with a json/rest configured proxy. And yes, you can load it up entirely, no need to use a MemoryProxy just for that. And I think you can implement paging in a grid unrelated to store paging, in other words you can have your whole data set loaded client-side and have your grids/dataviews page over the already loaded data, see ExtJS 4.0 Samples / Grids / Sliding Pager for a working example of that.

For syncing back to the server you'd use store.sync(), which also has the ability of batching multiple CRUD record operations. Doing it at predefined time intervals looks like an interesting idea, I'd never thought about it like that... But you might need to be careful to look at what is the user doing at the moment of syncing.

Personally I think I'd choose to implement it in a more standard way, like having a simple json/rest store and maybe sync at every record change, somehow I think it would be the most straightforward (and safest) approach, especially if you don't have related models (like one-to-many relationships).

19 Feb 2011, 6:36 PM
Here is my first tip that I have learned, expect to run into bugs. Since this isn't even a beta yet, there will be bugs.

20 Feb 2011, 6:06 AM
In other words, it might be risky to start building "a large application" with ExtJs 4 just yet.
There will still be changes in the API, lots of things will be improved, bugs will be corrected; but until a RC version comes out, you'd have to code lots of workarounds just to make it work and there's no point.
However, what you CAN do until the release is thinking/designing the architecture of your app taking into account the newly-introduced features (like the data package).

20 Feb 2011, 6:18 AM
Preplanning is a huge part of any app. It will shorten development time. I'm not saying not to work on the app, I'm just saying expect bugs and don't get discouraged.

When they were releasing beta version of Sencha Touch, it was very buggy. They worked through a lot but sometimes they had to break things in order to fix other things. Right now would be a great time to preplan and too start playing around with ExtJS 4 to learn the new features. What you learn now you can put into the app.

There are some things that probably won't change much like the data package. They brought over what's working with Sencha Touch for a few months now so I'm sure that won't be that buggy.

21 Feb 2011, 11:04 AM
Thanks for your suggestions. I've looked up the page that you linked to and the example is using a PagingMemoryProxy. However that proxy is paging over a data array. I need all the records to be loaded in the datastore and be able to page, sort and filter locally. For Ext3 there is a extension called Ext.ux.data.PagingStore that does exactly this. Is there any equivalent in Ext4 or do you know what methods i should be looking for to extend datastore?

You have right of the risk of getting data out of sync. I might do it in a more standard way but it's not as easy as setting autoSave to true. For example I have a spinner widget for each record field "quantity" in a dataview. If the user holds down the button the quantity field increases and fire the datastores “update” event. Good I can now update my dynamic basket and show the total price for the order. But the downside is that the record "update" event would trigger several ajax calls to the server. I have to do some tests and figure out when to save to the server.

Although Ext4 is in preview mode I successfully converted a lot of code already and it seems to be working pretty well. And you have right that there is a lot of preplaning to do. The visual have a lot of glitches but I'll leave that part when Ext4 beta/rc comes out. The documentation have lot of issues so many times it's easier to go through the source code to find out the right solution. But I'm very impressed with the new features of Ext4 so far.

21 Feb 2011, 11:28 AM
Part of the new data package that is in ExtJS 4 is the ability to natively page. So paging is by default included in all Stores. Sorting and filtering are also part of Stores and have been for some time now.

21 Feb 2011, 11:47 AM
Even if you have a spinner which fires multiple update events it doesn't mean your store will create ajax requests for those updates.
Updates only happen when/if you call store.sync(); there's no need to do any complicated/convoluted tests for that, you could do it when the grid row loses focus. Or put a save button somewhere...

21 Feb 2011, 11:55 AM
You may want to consider using DirectProxy as well. I've "heard" that you get Batch for free when using DirectProxy. Still, if it's 100 records... I don't think it would matter too much if you use REST or HTTPProxy.

Also, if your project is due within 6 months..I don't think I'll use version 4. Still, I understand the situation you're in.... because of the ExtJS MVC feature..most likely you'll have to do a lot of code redone for the upgrade... Of course, you don't necessarily have to use MVC but for the long run it's beneficial.

21 Feb 2011, 12:22 PM
The RestProxy will also "batch" your requests.
DirectProxy is interesting and quick-to-use but we're still waiting to see if/how it will be integrated with Ext 4.x data package. There's no DirectProxy in the API docs yet and I don't think I have seen it in the source code either.

Why wouldn't you use version 4 for a project due in 6 months?! The final version is hopefully just weeks away and once we'll have the betas rolling I think we could safely use it in our projects...

21 Feb 2011, 12:34 PM
Ok so the new data package supports paging. But I don't think it support to page its already loaded records (the way I want to use it).

For example if I have a standard store, dataview and paging toolbar.
I fill the store with 100 records via store.loadData or store.add
I now want to sort and view the records in my dataview using the default paging toolbar and page through the 10 pages.

How would i setup my store? I don't think there are any built in functionally for that or am I wrong? I must either change the logic of the paging toolbar, store or the proxy.

The new data package seems very promising. I hear you folks have lot of ideas. I must sit down and think this through how I want to approach this.

21 Feb 2011, 12:47 PM
I don't think you should literally read it as "final" version. Also, as Ed say this is "Major" release of ExtJS...meaning that there are many NEW codes that are different from ExtJS 3. So, this will in turn produce many bugs initially. Even after Sencha release the first official version... I doubt they'll say "A-Ok to use this for your production!" Most likely, their attitude will sound like "It's out~ go ahead and try to upgrade..if it doesn't work..then try again on next release". So, it could be that their first release maybe 100% bug free but the chance of that happening is probably slim.... This is why I think it'll take another 2~3 months of bug fixing before seriously thinking about switching... believe me.. I want to use ExtJS 4 ASAP too... but I don't want to switch for the sake of using ExtJS 4...I'm going to hold out as long as I can.... so maybe around May/June, I'll consider it.