Plato on Github
Report Home
application.js
Maintainability
78.85
Estimated # Bugs
0.54
Difficulty
13.98
SLOC/LSLOC
77 / 35
Function weight
By Complexity
By SLOC
// Application // ----------- // Contain and manage the composite application as a whole. // Stores and starts up `Region` objects, includes an // event aggregator as `app.vent` Marionette.Application = function(options){ this.initCallbacks = new Marionette.Callbacks(); this.vent = new Backbone.Wreqr.EventAggregator(); this.commands = new Backbone.Wreqr.Commands(); this.reqres = new Backbone.Wreqr.RequestResponse(); this.submodules = {}; _.extend(this, options); this.triggerMethod = Marionette.triggerMethod; }; _.extend(Marionette.Application.prototype, Backbone.Events, { // Command execution, facilitated by Backbone.Wreqr.Commands execute: function(){ var args = Array.prototype.slice.apply(arguments); this.commands.execute.apply(this.commands, args); }, // Request/response, facilitated by Backbone.Wreqr.RequestResponse request: function(){ var args = Array.prototype.slice.apply(arguments); return this.reqres.request.apply(this.reqres, args); }, // Add an initializer that is either run at when the `start` // method is called, or run immediately if added after `start` // has already been called. addInitializer: function(initializer){ this.initCallbacks.add(initializer); }, // kick off all of the application's processes. // initializes all of the regions that have been added // to the app, and runs all of the initializer functions start: function(options){ this.triggerMethod("initialize:before", options); this.initCallbacks.run(options, this); this.triggerMethod("initialize:after", options); this.triggerMethod("start", options); }, // Add regions to your app. // Accepts a hash of named strings or Region objects // addRegions({something: "#someRegion"}) // addRegions{{something: Region.extend({el: "#someRegion"}) }); addRegions: function(regions){ var that = this; _.each(regions, function (region, name) { var regionManager = Marionette.Region.buildRegion(region, Marionette.Region); that[name] = regionManager; }); }, // Removes a region from your app. // Accepts the regions name // removeRegion('myRegion') removeRegion: function(region) { this[region].close(); delete this[region]; }, // Create a module, attached to the application module: function(moduleNames, moduleDefinition){ // slice the args, and add this application object as the // first argument of the array var args = slice.call(arguments); args.unshift(this); // see the Marionette.Module object for more information return Marionette.Module.create.apply(Marionette.Module, args); } }); // Copy the `extend` function used by Backbone's classes Marionette.Application.extend = Marionette.extend;