Created
March 23, 2012 22:20
-
-
Save Gozala/2175647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// module: plugin-manager.js | |
var installable = require('./installable') | |
var events = require('./event-protocol') | |
function getPlugin() { /* ... */ } | |
function getDependents() { /* ... */ } | |
exports.start = function(plugin) { | |
// start all dependencies | |
plugin.dependencies.forEach(function(id) { | |
exports.start(getPlugin(id)) | |
}) | |
// notify that plugin is going to be started. | |
events.on(plugin, 'before:start', { ... }) | |
// start an actual plugin! | |
installable.on(plugin) | |
// notify that plugin was started. | |
events.emit(plugin, 'after:start', { ... }) | |
// track plugin stops so we can unload dependents | |
events.once(plugin, 'before:stop', function onstop() { | |
// stop all the plugins that depend on this one. | |
getDependents(plugin).forEach(exports.stop) | |
}) | |
} | |
exports.stop = function(plugin) { | |
events.emit(plugin, 'before:stop', {... }) | |
installable.off(plugin) | |
events.emit(plugin, 'after:stop', { ... }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BTW to be completely fare in reality I would have defined
Plugin
type where I would have implemented custom on / off that would have emitted events, but anyway I think this illustrates how two protocols may be used with a same type.