dissemination
Version:
Lightweight event/command library created to replace Backbone.Radio
41 lines (36 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var CommandMixin = {
handle: function handle(name, handler) {
if (!this._handlers) {
this._handlers = {};
}
if (this._handlers[name]) {
throw new TypeError("Another handler for command \"".concat(name, "\" is already registered."));
}
this._handlers[name] = handler;
},
unhandle: function unhandle(name) {
if (!this.handlerRegistered(name)) {
throw new TypeError("Handler for command \"".concat(name, "\" is not registered."));
}
delete this._handlers[name];
},
request: function request(name, options) {
if (!this.handlerRegistered(name)) {
throw new TypeError("Handler for command \"".concat(name, "\" is not registered."));
}
return this._handlers[name](options || {});
},
execute: function execute(name, options) {
this.request(name, options);
},
handlerRegistered: function handlerRegistered(name) {
return this._handlers && !!this._handlers[name];
}
};
var _default = CommandMixin;
exports["default"] = _default;