Plugin Architecture

Konstantin Käfer edited this page May 17, 2011 · 2 revisions

Modules providing functionality to a Bones application are called plugins. Every plugin has the same structure: An index.js file, and models, views, controllers, commands and/or servers in subdirectories. Bones’ core functionality is also implemented as a plugin; the only difference is that Bones loads it automatically.


// Load child plugins

// Load this plugin

if (module.parent) {
    // Start processing commands

Load order

Within a plugin, the default load order is:

  • Controllers
  • Models
  • Templates
  • Views
  • Servers
  • Commands

Among each kind, files are loaded alphabetically. If this doesn't work for you (e.g. when your Countries collection depends on the Country model), add requires to these files to index.js:

// Required to initialize loader for *.bones files

// Explicit load order

// Load the rest of this plugin

When loading multiple plugins, all files of one plugin are loaded before Bones proceeds to load the next plugin.

Components are sent to the client in the same order they were loaded on the server, i.e. you can influence the client's load order by using require() in index.js.