I've been trying to learn to work with Models and Stores. But the proxy bit is confusing me a lot. So I'm going to list out my understanding here - please point out the gaps in my understanding.
My understanding
- Models are used to represent domain objects.
- Models can be created by ModelManager, or by simply using the constructor
- Models are saved in Stores
- Stores may be in memory stores, or can be server stores. This is configured using Proxy.
- Proxy tells the store how to talk to a backing store - be that a JSON array, or a REST resource, or a simply configured URL via ajax.
- Stores are responsible for storing models, and Proxies are responsible for controlling/helping with that task.
- When a model's values are changed, its
dirty
flag gets set. It gets automatically cleared when the model is saved. (more in this later)
The part that confuses me
- Why is there a
proxy
config andsave
method on Model? I understand that models can only be stored on to stores. - Why is the
dirty
flag not cleared simply when I add a model object to a store? - When I add a model object to a store, why does the model not acquire the proxy configured with that store?
proxy
is a static configuration for a Model. Does that mean that we cannot use objects of a particular model with multiple data sources? By extension, does this mean having multiple stores for a single model essentially useless?- When we define a Store, are we defining a class (store-type, if we may call it that), or is it an instance of a store? Reason I ask is when we declare a grid, we simply pass it a store config as
store: 'MyApp.store.MyStore'
- does the grid instantiate a grid of that type, or is it simply using the store we've already instantiated?
Thanks!
PS: +50 bounty to the person who explains all this :) - will offer bounty after those 48 hours are over..