| module.exports = function createMenavEvents() { |
| return { |
| listeners: {}, |
|
|
| |
| on: function (event, callback) { |
| if (!this.listeners[event]) { |
| this.listeners[event] = []; |
| } |
| this.listeners[event].push(callback); |
| return this; |
| }, |
|
|
| |
| emit: function (event, data) { |
| if (this.listeners[event]) { |
| this.listeners[event].forEach((callback) => callback(data)); |
| } |
| return this; |
| }, |
|
|
| |
| off: function (event, callback) { |
| if (this.listeners[event]) { |
| if (callback) { |
| this.listeners[event] = this.listeners[event].filter((cb) => cb !== callback); |
| } else { |
| delete this.listeners[event]; |
| } |
| } |
| return this; |
| }, |
| }; |
| }; |
|
|