Barefoot.Router.Server

This mixin contains any server side specific code for the Barefoot.Router.

See also

Summary
Barefoot.Router.ServerThis mixin contains any server side specific code for the Barefoot.Router.
Functions
toStringString representation of this module.
preInitializeThis function is called before any initialization or constructor of the Barefoot.Router is executed.
routeThis replacements for the route function of Backbone.Router ensures that each route defined in the router is added to the Express.JS app.
navigateRewrites Backbone.Router.navigate to replicate its functionality when rendering the application on the server.
renderThis function initiates the rendering of the passed view.
startCalls the passed starter function, buffered in preInitialize.

Functions

toString

function toString()

String representation of this module.

preInitialize

function preInitialize(options)

This function is called before any initialization or constructor of the Barefoot.Router is executed.  It expects that the passed options object contains the following elements:

appAn Express.JS app
layoutTemplateThe minimal HTML skeleton to render the application into.  Example: “<html><head></head><body></body></html>”
startExpressAppA callback function which initiates the actual startup of the Express.JS app from above.

Each of these are copied into this router object directly to access them later on.

Parameters

(Object) options

route

function route(routeUri)

This replacements for the route function of Backbone.Router ensures that each route defined in the router is added to the Express.JS app.

The route function ensures that you have access to all cookies from the request via the cookieAdapter property of this router.

Parameters

(String) routeUriURI

Returns

The created Express.JS route

See also

navigate

function navigate(routeUri)

Rewrites Backbone.Router.navigate to replicate its functionality when rendering the application on the server.

Basically the callback for the given routeUri is picked and called.

Parameters

(String) routeUriThe URI of the route to navigate to

Returns

(Object) the value which the route callbacks returns.

render

function render(view)

This function initiates the rendering of the passed view.  This is done by loading the layout template into a cheerio DOM object.

Afterwards the presence of a main view object is checked.  If available, that main view gets rendered into the DOM.  In any case, the passed view gets rendered.

As a final step the presence of registered models in the application wide Barefoot.DataStore is checked.  If present, its content gets serialized into a script DOM element so the client can properly deserialize its state afterwards.  See Barefoot.Router.Client.start for the deserialization code.

The resulting HTML code is then sent to the client by using the Express.JS response object, buffered from the route callback in the route function.

Parameters

(Barefoot.View) viewThe view which should be rendered

See also

start

function start()

Calls the passed starter function, buffered in preInitialize.

The barefoot router extends the default backbone router by applying environment specific mixins to it
function toString()
String representation of this module.
function preInitialize(options)
This function is called before any initialization or constructor of the Barefoot.Router is executed.
function route(routeUri)
This replacements for the route function of Backbone.Router ensures that each route defined in the router is added to the Express.JS app.
function navigate(routeUri)
Rewrites Backbone.Router.navigate to replicate its functionality when rendering the application on the server.
function render(view)
This function initiates the rendering of the passed view.
function start()
Calls the passed starter function, buffered in preInitialize.
This mixin contains client specific code for the Barefoot.CookieAdapter component.
The DataStore is a core object and extends the Barefoot.Model.
function start()
When the application is coming up, this method gets called from Barefoot.Startup.Client.
Close