Skip to content

Commit

Permalink
Abstract debugLog text formatting into its own method
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebuilds committed Jan 28, 2015
1 parent 3a033f2 commit 194437d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/backbone.radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ Radio.noConflict = function () {
// get around the issues of lack of warnings when events are mis-typed.
Radio.DEBUG = false;

// Format debug text.
Radio._debugText = function(warning, eventName, channelName) {
return warning + (channelName ? ' on the ' + channelName + ' channel' : '') +
': "' + eventName + '"';
};

// This is the method that's called when an unregistered event was called.
// By default, it logs warning to the console. By overriding this you could
// make it throw an Error, for instance. This would make firing a nonexistent event
// have the same consequence as firing a nonexistent method on an Object.
Radio.debugLog = function(warning, eventName, channelName) {
if (!Radio.DEBUG) { return; }
var channelText = channelName ? ' on the ' + channelName + ' channel' : '';
if (console && console.warn) {
console.warn(warning + channelText + ': "' + eventName + '"');
if (Radio.DEBUG && console && console.warn) {
console.warn(Radio._debugText(warning, eventName, channelName));
}
};

Expand Down

0 comments on commit 194437d

Please sign in to comment.