This repository was archived by the owner on Oct 10, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Derick Bailey
committed
Sep 26, 2012
1 parent
0db6b08
commit 33ddf1b
Showing
6 changed files
with
169 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,104 @@ | ||
// Marionette.Wreqr v0.0.0 | ||
// ----------------------- | ||
// A basic Request/Response and Command pattern implementation | ||
// for Backbone.js applications | ||
// | ||
// Copyright 2012 Muted Solutions, LLC. All Rights Reserved | ||
|
||
// Request/Response | ||
// ---------------- | ||
|
||
(function(Marionette){ | ||
"use strict"; | ||
|
||
var handlers = {}; | ||
|
||
_.extend(Marionette.Application.prototype, { | ||
respondTo: function(name, handler, context){ | ||
var config = { | ||
handler: handler, | ||
context: context | ||
}; | ||
|
||
handlers[name] = config; | ||
}, | ||
|
||
request: function(name, args){ | ||
var config = handlers[name]; | ||
|
||
if (!config){ | ||
throw new Error("Request handler not found for '" + name + "'"); | ||
// Marionette.Wreqr, v0.0.0 | ||
// Copyright (c)2012 Derick Bailey, Muted Solutions, LLC. | ||
// Distributed under MIT license | ||
// http://github.com/marionettejs/marionette.wreqr | ||
Backbone.Marionette.Wreqr = (function(Backbone, Marionette, _){ | ||
"option strict"; | ||
var Wreqr = {}; | ||
|
||
Wreqr.Handlers = (function(Backbone, _){ | ||
"option strict"; | ||
|
||
var Handlers = function(){ | ||
"use strict"; | ||
this._handlers = {}; | ||
}; | ||
|
||
Handlers.extend = Backbone.Model.extend; | ||
|
||
_.extend(Handlers.prototype, { | ||
addHandler: function(name, handler, context){ | ||
var config = { | ||
callback: handler, | ||
context: context | ||
}; | ||
|
||
this._handlers[name] = config; | ||
}, | ||
|
||
getHandler: function(name){ | ||
var config = this._handlers[name]; | ||
|
||
if (!config){ | ||
throw new Error("Handler not found for '" + name + "'"); | ||
} | ||
|
||
return function(){ | ||
return config.callback.apply(config.context, arguments); | ||
}; | ||
}, | ||
|
||
removeHandler: function(name){ | ||
delete this._handlers[name]; | ||
}, | ||
|
||
removeAllHandlers: function(){ | ||
this._handlers = {}; | ||
} | ||
|
||
return config.handler.call(config.context, args); | ||
}, | ||
|
||
removeRequestHandler: function(name){ | ||
delete handlers[name]; | ||
}, | ||
|
||
clearRequestHandlers: function(){ | ||
handlers = {}; | ||
} | ||
}); | ||
|
||
})(Backbone.Marionette); | ||
|
||
// Command Pattern | ||
// --------------- | ||
|
||
(function(Marionette){ | ||
"use strict"; | ||
|
||
var handlers = {}; | ||
|
||
_.extend(Marionette.Application.prototype, { | ||
|
||
registerCommand: function(name, handler, context){ | ||
handlers[name] = { | ||
handler: handler, | ||
context: context | ||
}; | ||
}, | ||
|
||
removeCommand: function(name){ | ||
delete handlers[name]; | ||
}, | ||
|
||
clearCommands: function(){ | ||
handlers = {}; | ||
}, | ||
|
||
execute: function(name, args){ | ||
var config = handlers[name]; | ||
if (!config){ | ||
throw new Error("Handler not found for '" + name + "'"); | ||
}); | ||
|
||
return Handlers; | ||
})(Backbone, _); | ||
|
||
Wreqr.Commands = (function(Wreqr){ | ||
"option strict"; | ||
|
||
return Wreqr.Handlers.extend({ | ||
execute: function(name, args){ | ||
this.getHandler(name)(args); | ||
} | ||
|
||
config.handler.call(config.context, args); | ||
}); | ||
|
||
})(Wreqr); | ||
|
||
Wreqr.RequestResponse = (function(Wreqr){ | ||
"option strict"; | ||
|
||
return Wreqr.Handlers.extend({ | ||
request: function(name, args){ | ||
return this.getHandler(name)(args); | ||
} | ||
}); | ||
|
||
})(Wreqr); | ||
|
||
|
||
(function(){ | ||
"option strict"; | ||
|
||
console.log("foo"); | ||
|
||
if (Backbone && Backbone.Marionette && Backbone.Marionette.Application){ | ||
console.log("bar"); | ||
|
||
var commands = new Wreqr.Commands(); | ||
var reqres = new Wreqr.RequestResponse(); | ||
|
||
_.extend(Backbone.Marionette.Application.prototype, { | ||
commands: commands, | ||
execute: function(name, argObj){ | ||
commands.execute(name, argObj); | ||
}, | ||
|
||
requestResponse: reqres, | ||
request: function(name, argObj){ | ||
return reqres.request(name, argObj); | ||
} | ||
}); | ||
} | ||
}); | ||
})(); | ||
|
||
|
||
return Wreqr; | ||
})(Backbone, Backbone.Marionette, _); | ||
|
||
})(Backbone.Marionette); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,37 +26,43 @@ var categories = [ | |
var contacts = [ | ||
{ | ||
id: "09vsjk3209svdjh", | ||
name: "Joe Johnson", | ||
firstName: "Joe", | ||
lastName: "Johnson", | ||
email: "[email protected]", | ||
phone: "555-555-5555" | ||
}, | ||
{ | ||
id: "45890bdhj4590gf", | ||
name: "Jim Jimson", | ||
firstName: "Jim", | ||
lastName: "Jimson", | ||
email: "[email protected]", | ||
phone: "555-555-5556" | ||
}, | ||
{ | ||
id: "120985h4509vfh4", | ||
name: "Ben Benson", | ||
firstName: "Ben", | ||
lastName: "Benson", | ||
email: "[email protected]", | ||
phone: "555-555-5557" | ||
}, | ||
{ | ||
id: "9sd9123njkdas90", | ||
name: "Bob Robertson", | ||
firstName: "Bob", | ||
lastName: "Robertson", | ||
email: "[email protected]", | ||
phone: "555-555-5558" | ||
}, | ||
{ | ||
id: "lj32kjsd09xzcv3", | ||
name: "Amy Amerson", | ||
firstName: "Amy", | ||
lastName: "Amerson", | ||
email: "[email protected]", | ||
phone: "555-555-5559" | ||
}, | ||
{ | ||
id: "aa23j45hn45n536", | ||
name: "Julie Julerson", | ||
firstName: "Julie", | ||
lastName: "Julerson", | ||
email: "[email protected]", | ||
phone: "555-555-5560" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters