From 055a61a96cee06537705d94911e3478edae70914 Mon Sep 17 00:00:00 2001 From: max-barabash <48650035+max-barabash@users.noreply.github.com> Date: Sat, 20 Apr 2019 17:20:14 +0400 Subject: [PATCH] Update module --- index.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 7dca45f..bf50276 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,20 @@ +/** + * Барабаш Максим Сергеевич + */ module.exports = { - + eventList: [], /** * @param {String} event * @param {Object} subscriber * @param {Function} handler */ on: function (event, subscriber, handler) { - + this.eventList.push({ + event, + subscriber, + handler + }); + return this }, /** @@ -14,13 +22,23 @@ module.exports = { * @param {Object} subscriber */ off: function (event, subscriber) { - + for (let i = this.eventList.length - 1; i > 0; i--) { + if ((this.eventList[i].event === event)&&(this.eventList[i].subscriber === subscriber)) { + this.eventList.splice(i, 1); + } + } + return this }, /** * @param {String} event */ emit: function (event) { - + for (let i = 0; i < this.eventList.length; i++) { + if(this.eventList[i].event === event) { + this.eventList[i].handler.call(this.eventList[i].subscriber) + } + } + return this } };