/* * GNU AGPL-3.0 License * * Copyright (c) 2021 - present core.ai . All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License * for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://opensource.org/licenses/AGPL-3.0. * */ /*global less */ // jshint ignore: start // @INCLUDE_IN_API_DOCS /** * The global EventManager can be used to register named EventDispatchers so that events * can be triggered from anywhere without using require context. * * A global `window.EventManager` object is made available in phoenix that can be called anytime after AppStart. * * ## Usage * For Eg. Let's say we have an extension `drawImage` installed that wants to expose custom functionality to phoenix. * The Extension will first register named EventHandler like this: * ```js * // in drawImage/someExtensionModule.js module within the extension, do the following: * const EventDispatcher = brackets.getModule("utils/EventDispatcher"), * EventManager = brackets.getModule("utils/EventManager"); * EventDispatcher.makeEventDispatcher(exports); * * EventManager.registerEventHandler("drawImageHandler", exports); * ``` * Once the event handler is registered, we can trigger events on the named handler anywhere in phoenix * (inside or outside the extension) by using: * * ```js * EventManager.triggerEvent("drawImageHandler", "someEventName", "param1", "param2", ...); * ``` * @module utils/EventManager */ define(function (require, exports, module) { const _eventHandlerMap = {}; /** * Registers a named EventHandler. Event handlers are created using the call: * `EventDispatcher.makeEventDispatcher(Command.prototype);` * * @example