const isString = require('lodash.isstring');
const isFunc = require('lodash.isfunction');

const events = {};

function dispatch(event, data) {
    if (!isString(event)) {
        throw new TypeError('Event must be a string');
    }

    if (!events.hasOwnProperty(event)) {
        return null;
    }

    events[event].forEach((callback) => callback.call(null, data));
}

function observer(event, callback) {
    if (!isString(event)) {
        throw new TypeError('Event must be a string');
    }

    if (!isFunc(callback)) {
        throw new TypeError('Callback must be a function');
    }

    if (events.hasOwnProperty(event)) {
        events[event].push(callback);
    } else {
        events[event] = [callback];
    }
}

module.exports = {
    dispatch: dispatch,
    observer: observer
};

@@ -292,24 +292,67 @@
 ull;%0A    %7D%0A%0A
+    if (!data) %7B%0A        data = '';%0A    %7D%0A%0A
     events%5Be
@@ -378,16 +378,23 @@
 back) =%3E
+ data ?
  callbac
@@ -398,24 +398,26 @@
 back
-.call(null, data
+(data) : callback(
 ));%0A

support empty callbacks