1 var Runner = function($, _, app) {
\r
3 function getModuleInstance(moduleName) {
\r
4 var module = moduleInstances[moduleName] = (moduleInstances[moduleName] || app.modules[moduleName](new Sandbox(moduleName)));
\r
8 var bootstrappedData = {},
\r
10 moduleInstances = {},
\r
11 eventListeners = [];
\r
13 _.each(_.keys(app.modules || {}), function(moduleName) {
\r
14 if(_.contains(app.permissions[moduleName] || [], 'handleEvents')) {
\r
15 eventListeners.push(moduleName)
\r
21 var Sandbox = function(moduleName) {
\r
25 this.getBootstrappedData = function() {
\r
26 return bootstrappedData[moduleName];
\r
29 this.getTemplate = function(templateName) {
\r
30 return _.template($('[data-template-name="' + moduleName + '.' + templateName + '"]').html().trim());
\r
33 this.publish = function(eventName) {
\r
34 console.log(moduleName + ': ' + eventName);
\r
35 var eventArgs = Array.prototype.slice.call(arguments, 1)
\r
36 _.each(eventListeners, function(listenerModuleName) {
\r
37 var listener = moduleInstances[listenerModuleName];
\r
39 listener.handleEvent(moduleName, eventName, eventArgs);
\r
44 var permissions = app.permissions[moduleName];
\r
46 this.getModule = _.contains(permissions, 'getModule') ? function(requestedModuleName) {
\r
47 return getModuleInstance(requestedModuleName);
\r
50 this.getDOM = _.contains(permissions, 'getDOM') ? function() {
\r
51 return $(options.rootSelector);
\r
57 this.setBootstrappedData = function(moduleName, data) {
\r
58 bootstrappedData[moduleName] = data;
\r
61 this.start = function(_options) {
\r
62 options = _.extend({
\r
63 rootSelector: 'body'
\r
65 app.initModules.forEach(function(moduleName) {
\r
66 getModuleInstance(moduleName).start();
\r