From 0bc65b3b73e87b85c1b3ed7f278a3729af748d85 Mon Sep 17 00:00:00 2001 From: MattFloyd Date: Wed, 20 Jun 2018 14:51:28 -0400 Subject: [PATCH 1/4] Update README.md --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d7eb57..2eeb489 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 From 32795055fc7f3a3f946b3ef1d23804753e33b3e1 Mon Sep 17 00:00:00 2001 From: MattFloyd Date: Wed, 20 Jun 2018 14:52:30 -0400 Subject: [PATCH 2/4] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2eeb489..a5a2e69 100644 --- a/README.md +++ b/README.md @@ -70,10 +70,10 @@ EventBus.getEvents() 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); }; +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) ``` From f4c3bb616aca0c1bb5c219edf9789c0c08dee02d Mon Sep 17 00:00:00 2001 From: MattFloyd Date: Wed, 20 Jun 2018 14:56:13 -0400 Subject: [PATCH 3/4] add watcher functions --- src/EventBus.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/EventBus.js b/src/EventBus.js index f869710..072f286 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 Date: Wed, 20 Jun 2018 15:30:03 -0400 Subject: [PATCH 4/4] Update EventBus.js --- src/EventBus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EventBus.js b/src/EventBus.js index 072f286..398d4ac 100644 --- a/src/EventBus.js +++ b/src/EventBus.js @@ -84,7 +84,7 @@ for(var i=0; i