Skip to content

Commit 194437d

Browse files
committed
Abstract debugLog text formatting into its own method
1 parent 3a033f2 commit 194437d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/backbone.radio.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ Radio.noConflict = function () {
1717
// get around the issues of lack of warnings when events are mis-typed.
1818
Radio.DEBUG = false;
1919

20+
// Format debug text.
21+
Radio._debugText = function(warning, eventName, channelName) {
22+
return warning + (channelName ? ' on the ' + channelName + ' channel' : '') +
23+
': "' + eventName + '"';
24+
};
25+
2026
// This is the method that's called when an unregistered event was called.
2127
// By default, it logs warning to the console. By overriding this you could
2228
// make it throw an Error, for instance. This would make firing a nonexistent event
2329
// have the same consequence as firing a nonexistent method on an Object.
2430
Radio.debugLog = function(warning, eventName, channelName) {
25-
if (!Radio.DEBUG) { return; }
26-
var channelText = channelName ? ' on the ' + channelName + ' channel' : '';
27-
if (console && console.warn) {
28-
console.warn(warning + channelText + ': "' + eventName + '"');
31+
if (Radio.DEBUG && console && console.warn) {
32+
console.warn(Radio._debugText(warning, eventName, channelName));
2933
}
3034
};
3135

0 commit comments

Comments
 (0)