diff --git a/README.md b/README.md index 7d7eb57..a5a2e69 100644 --- a/README.md +++ b/README.md @@ -58,12 +58,25 @@ EventBus.dispatch(type, target, args ...) ### `getEvents` -For debugging purpose, it prints out the added listeners. +For debugging purposes, it prints out the added listeners. ```js EventBus.getEvents() ``` + +### `watch` + +For debugging purposes, add callbacks to fire when events are dispatched. + +```js +var onDispatch = function(type) { console.log("[EventBus] Dispatching: " + type) } +var onCallback = function(type) { console.log("[EventBus] Handling: " + type) } +var onAdd = function(type) { console.log("[EventBus] Adding Listener: " + type) } +var onRemove = function(type) { console.log("[EventBus] Removing Listener: " + type) } +EventBus.watch(onDispatch, onCallback, onAdd, onRemove) +``` + ## Usage ```js diff --git a/src/EventBus.js b/src/EventBus.js index f869710..398d4ac 100644 --- a/src/EventBus.js +++ b/src/EventBus.js @@ -12,9 +12,12 @@ var EventBusClass = {}; EventBusClass = function() { this.listeners = {}; + this.watchers = { onDispatch: null, onCallback: null, onAdd: null, onRemove: null }; }; EventBusClass.prototype = { addEventListener: function(type, callback, scope) { + if (this.watchers.onAdd != null) this.watchers.onAdd(type); + var args = []; var numOfArgs = arguments.length; for(var i=0; i