UNPKG

armisa-models

Version:
95 lines (94 loc) 3.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AttrEvent = void 0; class AttrEvent { constructor(data) { this.data = data; this.events = {}; this.get = (key) => { return this.data[key]; }; this.set = (value) => { // Object.assign(this.data, value); this.data = value; }; this.setKey = (key, value) => { this.data[key] = value; }; this.getAll = () => { return this.data; }; this.on = (eventName, callBack) => { const handlers = this.events[eventName] || []; handlers.push(callBack); this.events[eventName] = handlers; }; this.removeOn = (eventName) => { // this.events[eventName] = []; delete 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.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); }); }; 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.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'); }; } } exports.AttrEvent = AttrEvent;