licy

Asynchronous dependency and lifecycle management for Node and the browser

licy.js

Module lifecycle management for Node and the browser.

Repository: https://github.com/mantoni/licy.js

npm install licy

Browser packages are here: http://maxantoni.de/licy.js/.

  • Simple lifecycles (start & destroy)
  • Transparent restarts
  • Plugins use events to communicate
  • Auto-start plugins as required
  • Auto-queue events until plugin started

Examples can be found in the examples directory.

Is a hub.js event emitter instance.

All communication between the plugins happens via the licy event emitter.

licy.emit('foo.bar', 42, function (errresult) {
  // ... 
});

Please refer to the hub.js API documentation for the full list of supported features.

Registers a plugin with the given name and start function.

The start function takes the arguments (plugin[, callack]). The plugin is a hub.js view on the licy object, scoped to the name of the plugin.

If a callback is given, all events for this plugin will be queued until the callback was invoked. If the first argument to the callback is non-null, it is considered an error.

licy.plugin('server', function (plugin) {
  plugin.on('listen', function (port) {
    // ... 
  });
});

Registers multiple plugins. Supposed to be used with require to define plugins in their own modules and register them all in one go.

licy.plugins({
  'server': require('./server'),
  'router': require('./router'),
  // ... 
});

Starts all registered plugins.

The optional callback receives an error as the only argument.

Destroys all registered plugins.

The optional callback receives an error as the only argument.

Starts the plugin with the given name. This will invoke the plugins start function.

The optional callback receives an error as the only argument.

If an event is emitted on licy that starts with name, the plugin will be started automatically. All events are queued until the plugin is started.

Destroy the plugin with the given name. This will emit the destroy event on the plugin and remove all event handlers from it.

The optional callback receives an error as the only argument.

Destroys and then starts the plugin with the given name. This will emit the destroy event on the plugin, remove all event handlers from it and then invoke the start function of the plugin again.

The optional callback receives an error as the only argument.

Any events that are emitted for this plugin during the restart will be queued until the restart was successful.

Resets the licy singleton to the initial state. All listeners will be removed, all plugins unregistered and all states reset. This will not destroy the plugins or emit any events.

Use this in the tearDown function of your unit tests.

If you'd like to contribute to licy.js here is how to get started:

  • Fork the project on GitHub.
  • npm install will setup everything you need.
  • make lints the code with JSLint and runs all unit tests.
  • You can also make lint or make test individually.

Running the test cases in a browser requires nomo.js.

  • Run npm install -g nomo
  • Run nomo server from within the project directory.
  • Open http://localhost:4444/test in your browser.

To build a browser package containing the merged / minified scripts run make package.