Skip to content

Commit

Permalink
Add debug support
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Jun 1, 2014
1 parent 5dc619b commit 5d2f6b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Module dependences
*/

var debug = require('debug')('barracks');
var assert = require('assert');

/**
Expand Down Expand Up @@ -41,6 +42,7 @@ function Dispatcher() {
dispatcher.register = function(action, callback) {
assert('string' == typeof action, 'dispatcher.register: action must be a string');
assert('function' == typeof callback, 'dispatcher.register: callback must be a function');
debug('Registered action \'' + action + '\'.');

if (!this.callbacks[action]) this.callbacks[action] = [];
this.callbacks[action].push(callback);
Expand All @@ -60,6 +62,7 @@ dispatcher.register = function(action, callback) {
dispatcher.dispatch = function(action, data) {
assert(undefined !== data, 'dispatcher.dispatch: no data provided');
assert(undefined != this.callbacks[action], 'dispatcher.dispatch: action is not registered');
debug('Dispatched action: \'' + action + '\'.');

this.callbacks[action]
.forEach(function(callback) {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
"mocha": "~1.19.0",
"istanbul": "~0.2.10",
"coveralls": "~2.10.0"
},
"dependencies": {
"debug": "~0.8.1"
}
}

0 comments on commit 5d2f6b4

Please sign in to comment.