Paul
Paul

Reputation: 9445

in ExtJS, is it better to call Model.save() or Store.Sync()?

And what are the ramifications of each?

I see that Model.save(), for example, automatically refreshes the Model with results from the server. I'm not sure if sync() does.

Upvotes: 12

Views: 15073

Answers (1)

Molecular Man
Molecular Man

Reputation: 22386

automatically refreshes the Model with results from the server

Store.sync() refreshes modified records as well (provided you have setup the server response correctly).

So, technically, both methods do the same. However, in my opinion, you can use Model.save() only in one case: when you don't have store. Why? Because when you have store and nevertheless you use Model.save() that's mean that you have setup connection (proxy) configuration for both store and model. And that's mean that you have duplicated code which is potentially harder to maintain.

So, to summarize, you use Model.save() only if you use standalone model, without store (it may be the case when you have form which is not connected to any grid. So you create standalone model for such form), and you use Store.sync() in other cases.

Upvotes: 19

Related Questions