Skip to content

Derby "plugin" for direct component matching to routes, using component's load fn to do pre render tasks

License

Notifications You must be signed in to change notification settings

BBWeb/derby-load

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'));
// or
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) {
  // Do some data fetching before render
  model.fetch('data', function () {
    page.render(); // Will automatically trigger the proper rendering. If ns i passed in, it will override the default ns (which corresponds to the view associated with the component - see below)
  });
};

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.

// When this component is loaded through app.component('./mycomponent/index.js'), the subcomponent will automatically be loaded namespaced to the maincomponents name (and possible namespace), i.e. you will have two components loaded (from below component):
// maincomponent
// maincomponent:subcomponent
function MyComponent () {}

MyComponent.prototype.name = 'maincomponent'
MyComponent.prototype.components = [require('subcomponent')]

About

Derby "plugin" for direct component matching to routes, using component's load fn to do pre render tasks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published