1 define(['libs/jquery', 'libs/underscore'], function($, _) {
5 var Runner = function(app, modules) {
7 function getModuleInstance(moduleName) {
8 var module = moduleInstances[moduleName] = (moduleInstances[moduleName] || modules[moduleName](new Sandbox(moduleName)));
12 var bootstrappedData = {},
17 _.each(_.keys(modules || {}), function(moduleName) {
18 if(_.contains(app.permissions[moduleName] || [], 'handleEvents')) {
19 eventListeners.push(moduleName);
25 var Sandbox = function(moduleName) {
29 this.getBootstrappedData = function() {
30 return bootstrappedData[moduleName];
33 this.getTemplate = function(templateName) {
34 return _.template($('[data-template-name="' + moduleName + '.' + templateName + '"]').html().trim());
37 this.publish = function(eventName) {
38 var eventArgs = Array.prototype.slice.call(arguments, 1);
39 _.each(eventListeners, function(listenerModuleName) {
40 var listener = moduleInstances[listenerModuleName];
42 listener.handleEvent(moduleName, eventName, eventArgs);
47 var permissions = app.permissions[moduleName];
49 this.getModule = _.contains(permissions, 'getModule') ? function(requestedModuleName) {
50 return getModuleInstance(requestedModuleName);
53 this.getDOM = _.contains(permissions, 'getDOM') ? function() {
54 return $(options.rootSelector);
60 this.setBootstrappedData = function(moduleName, data) {
61 bootstrappedData[moduleName] = data;
64 this.start = function(_options) {
68 app.initModules.forEach(function(moduleName) {
69 getModuleInstance(moduleName).start();