Skip to content

Commit

Permalink
Refactor boots trappers. Add event bus for modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Rechkunov committed Mar 26, 2014
1 parent 75f1b01 commit a54420f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/BootstrapperBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = BootstrapperBase;

var path = require('path'),
util = require('util'),
EventEmitter = require('events').EventEmitter,
configPath = path.join(process.cwd(), 'config.json'),
config,
ServiceLocator = require('./ServiceLocator');
Expand Down Expand Up @@ -88,9 +89,14 @@ BootstrapperBase.prototype.create = function (configObject) {

/**
* Configures locator with all required type registrations.
* @param {Object} currentConfig Configuration object.
* @param {Object} configObject Configuration object.
* @param {ServiceLocator} locator Service locator to configure.
*/
BootstrapperBase.prototype.configure = function (currentConfig, locator) {
BootstrapperBase.prototype.configure = function (configObject, locator) {
var eventBus = new EventEmitter();
eventBus.setMaxListeners(0);
locator.registerInstance('eventBus', eventBus);

locator.registerInstance('config', configObject);

};
2 changes: 1 addition & 1 deletion lib/client/Bootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ function Bootstrapper() {
* @param {ServiceLocator} locator Service locator to configure.
*/
Bootstrapper.prototype.configure = function (configObject, locator) {
BootstrapperBase.prototype.configure.call(this, configObject, locator);
var loggerConfig = configObject.logger || {};
locator.registerInstance('logger', new Logger(loggerConfig.levels));
locator.registerInstance('config', configObject);
locator.registerInstance('window', window);

locator.register('moduleLoader', ModuleLoader, configObject, true);
Expand Down
3 changes: 2 additions & 1 deletion lib/server/Bootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function Bootstrapper() {
* @param {ServiceLocator} locator Service locator to configure.
*/
Bootstrapper.prototype.configure = function (configObject, locator) {
BootstrapperBase.prototype.configure.call(this, configObject, locator);
if (!configObject.clientTemplateEnginePath) {
configObject.clientTemplateEnginePath = path.relative(
path.join(__dirname, '..', 'client'),
Expand All @@ -71,8 +72,8 @@ Bootstrapper.prototype.configure = function (configObject, locator) {
require('./TemplateProvider'), configObject, true);
locator.register('clientBundleBuilder',
require('./ClientBundleBuilder'), configObject, true);

locator.registerInstance('logger', Log4js.getLogger('catberry'));
locator.registerInstance('config', configObject);
};

module.exports = new Bootstrapper();

0 comments on commit a54420f

Please sign in to comment.