1 define(['libs/jquery-1.9.1.min', 'libs/underscore-min'], function($, _) {
3 var Runner = function(app, modules) {
5 function getModuleInstance(moduleName) {
6 var module = moduleInstances[moduleName] = (moduleInstances[moduleName] || modules[moduleName](new Sandbox(moduleName)));
10 var bootstrappedData = {},
15 _.each(_.keys(modules || {}), function(moduleName) {
16 if(_.contains(app.permissions[moduleName] || [], 'handleEvents')) {
17 eventListeners.push(moduleName);
23 var Sandbox = function(moduleName) {
27 this.getBootstrappedData = function() {
28 return bootstrappedData[moduleName];
31 this.getTemplate = function(templateName) {
32 return _.template($('[data-template-name="' + moduleName + '.' + templateName + '"]').html().trim());
35 this.publish = function(eventName) {
36 console.log(moduleName + ': ' + eventName);
37 var eventArgs = Array.prototype.slice.call(arguments, 1);
38 _.each(eventListeners, function(listenerModuleName) {
39 var listener = moduleInstances[listenerModuleName];
41 listener.handleEvent(moduleName, eventName, eventArgs);
46 var permissions = app.permissions[moduleName];
48 this.getModule = _.contains(permissions, 'getModule') ? function(requestedModuleName) {
49 return getModuleInstance(requestedModuleName);
52 this.getDOM = _.contains(permissions, 'getDOM') ? function() {
53 return $(options.rootSelector);
59 this.setBootstrappedData = function(moduleName, data) {
60 bootstrappedData[moduleName] = data;
63 this.start = function(_options) {
67 app.initModules.forEach(function(moduleName) {
68 getModuleInstance(moduleName).start();