Barefoot.DataStore

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.

Environment Specific Mixins

In Depth

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.

Summary
Barefoot.DataStoreThe DataStore is a core object and extends the Barefoot.Model.
Functions
initializeEnsures that an empty registeredModels instance variable is created for the DataStore.
registerModelRegisters a specific Barefoot.Model or Barefoot.Collection with the given identifier.
registerCollectionAn alias for registerModel.
getRegisteredModelsReturns an object literal containing all currently registered models and collections.
findRegisteredModelIdentifierScans the registered models and collections for the given model.

Functions

initialize

function initialize()

Ensures that an empty registeredModels instance variable is created for the DataStore.

registerModel

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!

Important

Do not register “instances” of a model.  Instead, register its “class”.

Parameters

(String) identifierA unique identifier for this model type
(Barefoot.Model, Barefoot.Collection) modelModel/Collection type

registerCollection

function registerCollection(identifier,
model)

An alias for registerModel.

Parameters

(String) identifierA unique identifier for this model type
(Barefoot.Model, Barefoot.Collection) modelModel/Collection type

getRegisteredModels

function getRegisteredModels()

Returns an object literal containing all currently registered models and collections.

Returns

(Object) an object containing all registered Barefoot.Model and Barefoot.Collection

findRegisteredModelIdentifier

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.

Parameters

(<Barefoot.Model>, <Barefoot.Collection>) modelConcrete instance of a model or collection.

Returns

(String, undefined) the identifier of model if found, undefined if no match

For the moment, the Barefoot model does not introduce any new functionalities to Backbones model.
function initialize()
Ensures that an empty registeredModels instance variable is created for the DataStore.
function registerModel(identifier,
model)
Registers a specific Barefoot.Model or Barefoot.Collection with the given identifier.
For the moment, the Barefoot collection does not introduce any new functionalities to Backbones collection.
function registerCollection(identifier,
model)
An alias for registerModel.
function getRegisteredModels()
Returns an object literal containing all currently registered models and collections.
function findRegisteredModelIdentifier(model)
Scans the registered models and collections for the given model.
The barefoot view extends the default backbone view by applying an environment specific mixin to it.
This mixin contains client specific code for the Barefoot.DataStore component.
This mixin contains client specific code for the Barefoot.DataStore component.
function render(view)
This function initiates the rendering of the passed view.
Close