derby-load
Derby plugin for direct route component matching, using component's load fn to do route tasks
How to use
In your app's base file (index.js in app root), activate the plugin in a non-Derby-standard way:
require('derby-load')(app);
Then, use route methods either as usual, e.g.:
app.get(pattern, callback);
Or, directly binded to a component (which has NOT previously been added using app.component)
app.get(pattern, require('myComponent'));
app.get(pattern, require('myComponent'), {viewName: 'someViewName', ns: 'namespace to be passed into page.render'});
In your component, you can add a (optional) load fn to load things before page.render is called, e.g.:
MyComponent.prototype.load = function (page, model, params, next) {
model.fetch('data', function () {
page.render();
});
};
Notes:
- app.get will automatically bind the component upon initialization of the app
- When the route gets triggered, it will automatically render the component
- The component needs to have a view specified, if not the viewName options attribute is passed along:
MyComponent.prototype.view = 'myView'
Adds the possibility to add a subcomponents on your Component prototype - i.e. without access to app. E.g.
function MyComponent () {}
MyComponent.prototype.name = 'maincomponent'
MyComponent.prototype.components = [require('subcomponent')]