PDA

View Full Version : should I use proxy in the Ext.data.model or Ext.data.store



haha001
9 May 2014, 6:08 AM
When I'm learning Ext JS, I found some books put the proxy in Ext.data.model, others put proxy in Ext.data.store. Which one should I follow? Or which way is better? Thanks!

scottmartin
9 May 2014, 6:38 AM
I do not think there is a better option, but a preference.

If you do not need a model, then it is obvious.

My earlier choice was to place it in the model, but lately I have been adding it to the store and only defining the fields in the model. This makes the code cleaner in my opinion.

I am sure you will get comments on both sides.

jsakalos
9 May 2014, 11:15 PM
I place proxy/reader/writer configuration it in model because this way the model can be used standalone, w/o a store, and is still capable of communicating with server.

For example, form can now be backed by record (model instance), no store is required in this case, but I still want to load/save form data via its record.

Technically, there is always only one instance of proxy, whether you configure it on model or store and if it is defined on model store takes the configuration from the model.

skirtle
10 May 2014, 2:51 AM
I tend to go with...

If the proxy loads one model per request then put it on the model.
If the proxy loads multiple models per request then put it on the store.
If the same proxy configuration would work for both purposes then put it on the model and let the store inherit it.

jsakalos
10 May 2014, 11:25 AM
Yeah Den, this was the logic I also initially thought about.

But then, for the sake of consistency, I decided for model always. I'm supervising development of a huge app currently and it was much easier to tell developers "put it on model" than to explain why it cannot be on the store in one particular case and why they should move it from model to store in other case.

No technical difference, just convention.

skirtle
10 May 2014, 7:05 PM
Wouldn't that cause problems once you have multiple stores loading the same model using different criteria? Then you'd have to start adding proxies to some stores anyway. Bang goes the convention.

jsakalos
10 May 2014, 11:54 PM
Hmm, haven't run into any problems. What specific situation could cause that what you mean?