tnt-form
Version:
45 lines (34 loc) • 1.49 kB
JavaScript
;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Eventable = function () {
function Eventable() {
_classCallCheck(this, Eventable);
}
_createClass(Eventable, [{
key: 'on',
value: function on(eventName, cb) {
if (!this.eventListeners) {
this.eventListeners = [];
}
if (typeof this.eventListeners[eventName] === 'undefined') {
this.eventListeners[eventName] = [];
}
this.eventListeners[eventName].push(cb);
}
}, {
key: 'trigger',
value: function trigger(eventName, arg) {
if (!this.eventListeners) {
this.eventListeners = [];
}
if (typeof this.eventListeners[eventName] !== 'undefined') {
this.eventListeners[eventName].forEach(function (cb) {
cb(arg);
});
}
}
}]);
return Eventable;
}();
module.exports = Eventable;