Permalink
Browse files

providing command pattern and request/response pattern from Applicati…

…on instance, directly
  • Loading branch information...
derickbailey committed Oct 3, 2012
1 parent 1a6e42b commit a980f59f0f0637c946f252c1234ae11f26e63394
Showing with 52 additions and 0 deletions.
  1. +20 −0 spec/javascripts/commands.spec.js
  2. +20 −0 spec/javascripts/requestResponse.spec.js
  3. +12 −0 src/marionette.application.js
@@ -0,0 +1,20 @@
+describe("application commands", function(){
+
+ describe("when creating an instance of an Application", function(){
+ var App;
+
+ beforeEach(function(){
+ App = new Marionette.Application();
+ });
+
+ it("should provide command execution framework", function(){
+ expect(App.commands).toBeInstanceOf(Backbone.Wreqr.Commands);
+ });
+
+ it("should allow execution of commands directly", function(){
+ expect(typeof App.execute).toBe("function");
+ });
+
+ });
+
+});
@@ -0,0 +1,20 @@
+describe("application request/response", function(){
+
+ describe("when creating an instance of an Application", function(){
+ var App;
+
+ beforeEach(function(){
+ App = new Marionette.Application();
+ });
+
+ it("should provide request/response framework", function(){
+ expect(App.reqres).toBeInstanceOf(Backbone.Wreqr.RequestResponse);
+ });
+
+ it("should allow direct request", function(){
+ expect(typeof App.request).toBe("function");
+ });
+
+ });
+
+});
@@ -7,13 +7,25 @@
Marionette.Application = function(options){
this.initCallbacks = new Marionette.Callbacks();
this.vent = new Marionette.EventAggregator();
+ this.commands = new Backbone.Wreqr.Commands();
+ this.reqres = new Backbone.Wreqr.RequestResponse();
this.submodules = {};
var eventBinder = new Marionette.EventBinder();
_.extend(this, eventBinder, options);
};
_.extend(Marionette.Application.prototype, Backbone.Events, {
+ // Command execution, facilitated by Backbone.Wreqr.Commands
+ execute: function(){
+ this.commands.execute.apply(this.commands, arguments);
+ },
+
+ // Request/response, facilitated by Backbone.Wreqr.RequestResponse
+ request: function(){
+ return this.reqres.request.apply(this.reqres, arguments);
+ },
+
// 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.

0 comments on commit a980f59

Please sign in to comment.