The DataStore is a core object and extends the Barefoot.Model.
When rendering a Barefoot.View on the server, it will probably create, read and modify Models and Collections. Delivering the views rendered HTML markup to the client is quite simple and straightforward, but never enough: To set up and boot your application inside the users browser barefoot needs to have the same information as it was present on the server after finishing the rendering process.
The DataStore hops in at exactly this point: It provides a centralized storage for Models and Collections which is serialized after rendering a view on the server automatically. On the client, it checks for the presence of such serialized data and deserializes it automatically if needed.
This has one small, but important impact when developing your application with barefoot: All Models and Collections you need to transfer to the client after a server side rendering needs to be stored inside the DataStore.
For further information, please refer to the regarding environment specific mixins.
You may wonder how the DataStore accomplishes the data transfer from the server to the client.
When rendering a View, the Barefoot.Router.Server.render function embeds a script DOM element into the HTML body element containing a global function. <Barefoot.Startup.Client> checks for the presence of this function and initiates the deserialization of the contained DataStore information if needed.
Barefoot. | The DataStore is a core object and extends the Barefoot.Model. |
Functions | |
initialize | Ensures that an empty registeredModels instance variable is created for the DataStore. |
registerModel | Registers a specific Barefoot.Model or Barefoot.Collection with the given identifier. |
registerCollection | An alias for registerModel. |
getRegisteredModels | Returns an object literal containing all currently registered models and collections. |
findRegisteredModelIdentifier | Scans the registered models and collections for the given model. |
function registerModel( identifier, model )
Registers a specific Barefoot.Model or Barefoot.Collection with the given identifier. This information is needed when serializing the DataStore for transferring data to the client.
You will not be able to serialize a store containing models which were not registered before!
Do not register “instances” of a model. Instead, register its “class”.
(String) identifier | A unique identifier for this model type |
(Barefoot.Model, Barefoot.Collection) model | Model/Collection type |
function registerCollection( identifier, model )
An alias for registerModel.
(String) identifier | A unique identifier for this model type |
(Barefoot.Model, Barefoot.Collection) model | Model/Collection type |
function getRegisteredModels()
Returns an object literal containing all currently registered models and collections.
(Object) an object containing all registered Barefoot.Model and Barefoot.Collection
function findRegisteredModelIdentifier( model )
Scans the registered models and collections for the given model. When found, the identifier of the registration gets returned. Otherwise undefined is returned.
(<Barefoot.Model>, <Barefoot.Collection>) model | Concrete instance of a model or collection. |
(String, undefined) the identifier of model if found, undefined if no match
Ensures that an empty registeredModels instance variable is created for the DataStore.
function initialize()
Registers a specific Barefoot.Model or Barefoot.Collection with the given identifier.
function registerModel( identifier, model )
An alias for registerModel.
function registerCollection( identifier, model )
Returns an object literal containing all currently registered models and collections.
function getRegisteredModels()
Scans the registered models and collections for the given model.
function findRegisteredModelIdentifier( model )
This function initiates the rendering of the passed view.
function render( view )