armisa-models
Version:
models of armisa!
45 lines (44 loc) • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Events = void 0;
class Events {
constructor() {
this.events = {};
this.onSimulateKeyDown = (key, propertyName, callBack) => {
this.on(('form.control.simulate.keyDown' + key.toString() + propertyName.toString()), callBack);
};
this.removeOnSimulateKeyDown = (key, propertyName) => {
this.removeOn(('form.control.simulate.keyDown' + key.toString() + propertyName.toString()));
};
this.SimulateKeyDown = (key, propertyName, ...args) => {
this.trigger(('form.control.simulate.keyDown' + key.toString() + propertyName.toString()), args);
};
this.on = (eventName, callBack) => {
const handlers = this.events[eventName] || [];
handlers.push(callBack);
this.events[eventName] = handlers;
};
this.removeOn = (eventName) => {
this.events[eventName] = [];
};
this.onControl = (eventName, propertyName, callBack) => {
this.on((eventName + propertyName), callBack);
};
this.triggerControl = (eventName, propertyName, ...args) => {
this.trigger((eventName + propertyName), args);
};
this.removeOnControl = (eventName, propertyName) => {
this.removeOn((eventName + propertyName));
};
this.trigger = (eventName, ...args) => {
const handlers = this.events[eventName];
if (!handlers || handlers.length === 0) {
return;
}
handlers.forEach((callback) => {
callback.apply(null, args);
});
};
}
}
exports.Events = Events;