An application level request/response system. This allows components in an application to request some information or work be done by another part of the app, but without having to be explicitly coupled to the component that is performing the work.
A return response is expected when making a request.
Facilitated by Backbone.Wreqr's RequestResponse object.
To register a command, call App.reqres.setHandler
and provide a name for
the command to handle, and a callback method.
var App = new Marionette.Application();
App.reqres.setHandler("foo", function(bar){
return bar + "-quux";
});
To execute a command, either call App.reqres.request
or the more direct
route of App.request
, providing the name of the command to execute and
any parameters the command needs:
App.request("foo", "baz"); // => returns "baz-quux"
To remove a request handler, call App.reqres.removeHandler
and provide the
name of the request handler to remove.
To remove all request handlers, call App.reqres.removeAllHandlers()
.
To replace a request handler, simply register a new handler for an existing request handler name. There can be only one request handler for a given request name.