Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (31 sloc) 1.32 KB

Marionette.commands

An application level command execution system. This allows components in an application to state that some work needs to be done, but without having to be explicitly coupled to the component that is performing the work.

No response is allowed from the execution of a command. It's a "fire-and-forget" scenario.

Facilitated by Backbone.Wreqr's Commands object.

Register A Command

To register a command, call App.commands.register and provide a name for the command to handle, and a callback method.

var App = new Marionette.Application();

App.commands.register("foo", function(bar){
  console.log(bar);
});

Execute A Command

To execute a command, either call App.commands.execute or the more direct route of App.execute, providing the name of the command to execute and any parameters the command needs:

App.execute("foo", "baz");
// outputs "baz" to the console, from command registered above

Remove / Replace Commands

To remove a command, call App.commands.removeHandler and provide the name of the command to remove.

To remove all commands, call App.commands.removeAllHandlers().

To replace a command, simply register a new handler for an existing command name. There can be only one command handler for a given command name.

Jump to Line
Something went wrong with that request. Please try again.