Skip to content

Instantly share code, notes, and snippets.

@jcblw
Last active October 1, 2015 04:20
Show Gist options
  • Select an option

  • Save jcblw/f20504df98168411fc13 to your computer and use it in GitHub Desktop.

Select an option

Save jcblw/f20504df98168411fc13 to your computer and use it in GitHub Desktop.
Sheru Controllers

Sheru Controller

Sheru is an isomorphic framework that used jsdom to create server rendered pages. It is based on Backbone and Handlebars.

Sheru controllers

Sheru controllers are very important. They are the main piece that interfaces directly with both the server and the client.

Controllers have a life cycle.

Controller::initialize - Server/Client

This initializes the controller and allows for basic structures that the controller needs to run.

Controller::getLayoutData - Server/Client

This is a hook in the rendering process that will grab data from a internal or external source. This is meant to be where all the setup calls should be made. decide on wether it smarter to have a promise returned or call a callback or maybe both

Controller::getLayout - Server/Client

This will grab the template needed to render page. The first parameter to this function is url data. This will be a url fragments and query information. This should be mockable to allow for the server side to pass this data in explicitly to render pages. The second param is the data from getLayoutData.

Controller::layoutDidRender - Server/Client

This is a hook to know that the layout rendered. For the server this indicates to pull all data from the layout and spit it into the page.

Controller::beforeLayoutSaved - Server

This is a pre hook meant to allow for mutation to html structure before putting it into a file.

Controller::layoutDidMount - Client

This indicates that the layout mounted and that events are started.

Controller::shouldLayoutUpdate - Client

This is a method that allows you to know if the layout should update. It passes in any new data as well as new url information If available.

Controller::layoutWillUpdate - Client

This is a place where you can update your controllers structures/cache to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment