@inweb/eventemitter2
Version:
JavaScript event emitter
25 lines (23 loc) • 2.24 kB
JavaScript
///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2002-2026, Open Design Alliance (the "Alliance").
// All rights reserved.
//
// This software and its documentation and related materials are owned by
// the Alliance. The software may only be incorporated into application
// programs owned by members of the Alliance, subject to a signed
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable
// trade secrets of the Alliance and its suppliers. The software is also
// protected by copyright law and international treaty provisions. Application
// programs incorporating this software must include the following statement
// with their copyright notices:
//
// This application incorporates Open Design Alliance software pursuant to a
// license agreement with Open Design Alliance.
// Open Design Alliance Copyright (C) 2002-2026 by Open Design Alliance.
// All rights reserved.
//
// By use of this software, its documentation or related materials, you
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ODA=e.ODA||{})}(this,function(e){"use strict";e.EventEmitter2=class{constructor(){this._listeners={}}addEventListener(e,t){return void 0===this._listeners[e]&&(this._listeners[e]=[]),this._listeners[e].push(t),this}removeEventListener(e,t){if(void 0===this._listeners[e])return this;const s=this._listeners[e].filter(e=>e!==t);return 0!==s.length?this._listeners[e]=s:delete this._listeners[e],this}removeAllListeners(e){return e?delete this._listeners[e]:this._listeners={},this}emitEvent(e){if(void 0===this._listeners[e.type])return!1;return this._listeners[e.type].slice().forEach(t=>t.call(this,e)),!0}on(e,t){return this.addEventListener(e,t)}off(e,t){return this.removeEventListener(e,t)}emit(e,...t){return"string"==typeof e?this.emitEvent({type:e,args:t}):"object"==typeof e&&this.emitEvent(e)}}});