UNPKG

@abaplint/runtime

Version:
48 lines 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ABAPEventing = void 0; class ABAPEventing { registrations = {}; setHandler(event, methods, forObject, activation) { if (activation === false) { throw new Error("ABAPEventing.setHandler: deactivation not supported, todo"); } else if (methods.length === 0) { throw new Error("ABAPEventing.setHandler: no methods provided"); } if (!this.registrations[event.EVENT_CLASS]) { this.registrations[event.EVENT_CLASS] = {}; } if (!this.registrations[event.EVENT_CLASS][event.EVENT_NAME]) { this.registrations[event.EVENT_CLASS][event.EVENT_NAME] = []; } const ref = forObject === "ALL" ? "ALL" : new WeakRef(forObject); const handlers = this.registrations[event.EVENT_CLASS][event.EVENT_NAME]; // todo: tackle duplicates handlers.push({ handlers: methods, forObject: ref, }); } // todo: cleanup of dead WeakRefs async raiseEvent(event, me, parameters) { const handlers = this.registrations[event.EVENT_CLASS]?.[event.EVENT_NAME]; if (handlers === undefined) { return; } for (const handler of handlers) { if (handler.forObject === "ALL") { for (const method of handler.handlers) { await method(parameters); } } else if (handler.forObject.deref() === me) { for (const method of handler.handlers) { await method(parameters); } } } } } exports.ABAPEventing = ABAPEventing; //# sourceMappingURL=abap_eventing.js.map