-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Extract common listener behaviour from progress formatter * Extract stats journal from progress formatter Theses changes will ease the implementation of new listeners (e.g. the pretty, JSON and jUnit formatters).
- Loading branch information
Showing
19 changed files
with
2,029 additions
and
1,641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,38 @@ | ||
var Listener = {}; | ||
var Listener = function () { | ||
var self = { | ||
hear: function hear(event, callback) { | ||
if (self.hasHandlerForEvent(event)) { | ||
var handler = self.getHandlerForEvent(event); | ||
handler(event, callback); | ||
} else { | ||
callback(); | ||
} | ||
}, | ||
|
||
hasHandlerForEvent: function hasHandlerForEvent(event) { | ||
var handlerName = self.buildHandlerNameForEvent(event); | ||
return self[handlerName] != undefined; | ||
}, | ||
|
||
buildHandlerNameForEvent: function buildHandlerNameForEvent(event) { | ||
var handlerName = | ||
Listener.EVENT_HANDLER_NAME_PREFIX + | ||
event.getName() + | ||
Listener.EVENT_HANDLER_NAME_SUFFIX; | ||
return handlerName; | ||
}, | ||
|
||
getHandlerForEvent: function getHandlerForEvent(event) { | ||
var eventHandlerName = self.buildHandlerNameForEvent(event); | ||
return self[eventHandlerName]; | ||
} | ||
}; | ||
return self; | ||
}; | ||
|
||
Listener.EVENT_HANDLER_NAME_PREFIX = 'handle'; | ||
Listener.EVENT_HANDLER_NAME_SUFFIX = 'Event'; | ||
|
||
Listener.ProgressFormatter = require('./listener/progress_formatter'); | ||
Listener.StatsJournal = require('./listener/stats_journal'); | ||
module.exports = Listener; |
Oops, something went wrong.