UNPKG

armisa-models

Version:
84 lines (83 loc) 3.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Eventing = void 0; class Eventing { constructor() { this.events = {}; this.on = (eventName, callBack) => { const handlers = this.events[eventName] || []; handlers.push(callBack); this.events[eventName] = handlers; }; this.removeOn = (eventName) => { this.events[eventName] = []; }; this.reOn = (name, callBack) => { const handlers = this.events[name]; if (!handlers || handlers.length === 0) { return; } this.events[name].map((i) => (i = callBack)); }; this.trigger = (eventName, ...args) => { const handlers = this.events[eventName]; if (!handlers || handlers.length === 0) { return; } handlers.forEach((callback) => { callback.apply(null, args); }); }; this.onCodeSimulateKeyDown = (key, propertyName, callBack) => { this.on(('code.simulate.keyDown' + key.toString() + propertyName), callBack); }; this.codeSimulateKeyDown = (key, propertyName, ...args) => { this.trigger(('code.simulate.keyDown' + key.toString() + propertyName), args); }; this.removeOnCodeSimulateKeyDown = (key, propertyName) => { this.removeOn(('code.simulate.keyDown' + key.toString() + propertyName)); }; this.triggerChangeFilterOfPage = () => { this.trigger('factory.class.filter.change'); }; this.onFactoryClassWillUnmount = (callBack) => { this.on('factory.class.will.unmount', callBack); }; this.factoryClassWillUnmount = () => { this.trigger('factory.class.will.unmount'); this.removeOn('factory.class.will.unmount'); }; 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.clearAllCallback = () => { this.events = {}; }; this.controlWillUnmounts = []; this.onControlWillUnmount = (propertyName, callBack) => { if (!this.controlWillUnmounts.find(i => i === propertyName)) { this.controlWillUnmounts.push(propertyName); } this.on(('control.will.unmount' + propertyName), callBack); }; this.removeOnControlWillUnmount = (propertyName) => { this.controlWillUnmounts = this.controlWillUnmounts.filter(i => i !== propertyName); this.removeOn(('control.will.unmount' + propertyName)); }; this.controlWillUnmount = (propertyName, ...args) => { this.trigger(('control.will.unmount' + propertyName), args); }; this.allControlsWillUnmount = () => { this.controlWillUnmounts.forEach(i => { this.controlWillUnmount(i); }); }; } } exports.Eventing = Eventing;