PDA

View Full Version : Proxy in Model V/S Proxy in Store



ashetti
25 Aug 2014, 3:33 AM
I am new to Sench ExtJS / Touch.
My question might be silly but could not find a answer on Google hence putting it here.

What are the pros and cons of having Proxy in Model compared to having Proxy in Store.

I have found following stack post
http://stackoverflow.com/questions/21845145/extjs-model-proxy-vs-store-proxy
http://stackoverflow.com/questions/7404870/extjs-how-to-use-proxy-model-how-are-they-related

I am not getting the piratical application of this. Where as ethical for a better design I feel that I should always have proxy in store.

Also when we associate multiple model with store it is via association, hence there can exists cluster of model by them self.

I might be wrong in my statement please correct me if I am wrong. And help me understand the advantage of having proxy in store vs proxy in model.

skirtle
26 Aug 2014, 3:01 AM
If you want to load or save an individual model instance then it will need to have a proxy on that model. There is no store involved in this process.

If you want to load or save a list of models then that's a store and the proxy should be on the store.

If your server API is such that sharing the same proxy between the model and store is possible then you can save yourself some duplication by just putting it on the model and inheriting it on the store. This is often the case when using the REST proxy.

ashetti
26 Aug 2014, 3:07 AM
If you want to load or save an individual model instance then it will need to have a proxy on that model. There is no store involved in this process.

If you want to load or save a list of models then that's a store and the proxy should be on the store.

If your server API is such that sharing the same proxy between the model and store is possible then you can save yourself some duplication by just putting it on the model and inheriting it on the store. This is often the case when using the REST proxy.

As per my knowledge again we can have only one model and have association to associate it with multi child model. Then we don't need a store. But are you suggesting we can load multiple models in parallel in a store? If so can you explain me how ?

Correct my understanding if I am wrong.

skirtle
26 Aug 2014, 3:28 AM
I don't understand what you're asking.

If you load your associations using inline data then there's no separate load so the proxy is often not needed.

If you load them separately then you'll need a proxy.

A hasmany association will use a store which can be configured just like any other store via the storeConfig. If you use the same model for a lot of different associations you'd either need to configure the proxy on each store or use the built-in filtering to share the proxy from the model. The latter approach will only work if your server API follows a suitable convention.

The other association types load a single model by id, so they would need a proxy on the model itself.