This mixin contains any server side specific code for the Barefoot.Router.
Barefoot. | This mixin contains any server side specific code for the Barefoot.Router. |
Functions | |
toString | String representation of this module. |
preInitialize | This function is called before any initialization or constructor of the Barefoot.Router is executed. |
route | This replacements for the route function of Backbone.Router ensures that each route defined in the router is added to the Express.JS app. |
navigate | Rewrites Backbone.Router.navigate to replicate its functionality when rendering the application on the server. |
render | This function initiates the rendering of the passed view. |
start | Calls the passed starter function, buffered in 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:
app | An Express.JS app |
layoutTemplate | The minimal HTML skeleton to render the application into. Example: “<html><head></head><body></body></html>” |
startExpressApp | A 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.
(Object) options
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.
(String) routeUri | URI |
The created Express.JS route
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.
(String) routeUri | The URI of the route to navigate to |
(Object) the value which the route callbacks returns.
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.
(Barefoot.View) view | The view which should be rendered |
function start()
Calls the passed starter function, buffered in preInitialize.
String representation of this module.
function toString()
This function is called before any initialization or constructor of the Barefoot.Router is executed.
function preInitialize( options )
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 route( routeUri )
Rewrites Backbone.Router.navigate to replicate its functionality when rendering the application on the server.
function navigate( routeUri )
This function initiates the rendering of the passed view.
function render( view )
Calls the passed starter function, buffered in preInitialize.
function start()
When the application is coming up, this method gets called from Barefoot.Startup.Client.
function start()