From 5f1664698b3343fa3a3b7bd2e5edf8651de1d2c3 Mon Sep 17 00:00:00 2001 From: Ramprasad Rajendran Date: Wed, 1 Feb 2017 17:52:47 +0530 Subject: [PATCH] Special event logAllEvents will trigger all events --- package.json | 2 +- src/event_manager.js | 6 +++++- test/event_manager.js | 15 +++++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index fd88368..3ef806a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "devkithelper", - "version": "3.0.4", + "version": "3.0.5", "devkit": { "clientPaths": { "DevkitHelper": "src" diff --git a/src/event_manager.js b/src/event_manager.js index d29c8f9..bf34922 100644 --- a/src/event_manager.js +++ b/src/event_manager.js @@ -25,11 +25,15 @@ exports = (function () { obj.emit = function (signal, data) { this.plugins.forEach(function (plugin) { - var fn = modules[plugin][toCamel(signal)]; + var fn = modules[plugin][toCamel(signal)], + all_evt = modules[plugin].logAllEvents; if (typeof fn === 'function') { fn(data); } + if(typeof all_evt === 'function') { + all_evt(signal, data); + } }); }; diff --git a/test/event_manager.js b/test/event_manager.js index 98592fb..90110fd 100644 --- a/test/event_manager.js +++ b/test/event_manager.js @@ -27,13 +27,24 @@ describe('EventManager', function () { }); describe('emit', function () { - it('call the plugin function if registered', function (done) { + it('calls the plugin function if registered', function (done) { event_manager.register('test', ['test_sdk']); - test_sdk.transactionComplete = function () { done(); }; + test_sdk.transactionComplete = function () { + done(); + test_sdk.transactionComplete = false; + }; event_manager.emit('transaction-complete', {cost: 100}); }); }); + describe('logAllEvents', function () { + it('logAllEvents would get called for any event', function (done) { + event_manager.register('test', ['test_sdk']); + test_sdk.logAllEvents = function() { done(); }; + event_manager.emit('transaction-complete', {data: 100}); + }); + }); + describe('toCamel()', function () { it('should convert - to camel case', function () { assert.strictEqual('functionName',