Skip to content

Commit

Permalink
Special event logAllEvents will trigger all events
Browse files Browse the repository at this point in the history
  • Loading branch information
rampr committed Feb 1, 2017
1 parent 3996565 commit 5f16646
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "devkithelper",
"version": "3.0.4",
"version": "3.0.5",
"devkit": {
"clientPaths": {
"DevkitHelper": "src"
Expand Down
6 changes: 5 additions & 1 deletion src/event_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
};

Expand Down
15 changes: 13 additions & 2 deletions test/event_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 5f16646

Please sign in to comment.