UNPKG

@robotlegsjs/phaser

Version:

RobotlegsJS integration with Phaser Scene Manager

167 lines 8.52 kB
"use strict"; // ------------------------------------------------------------------------------ // Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved. // // NOTICE: You are permitted to use, modify, and distribute this file // in accordance with the terms of the license agreement accompanying it. // ------------------------------------------------------------------------------ Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractMediator = void 0; var tslib_1 = require("tslib"); var core_1 = require("@robotlegsjs/core"); var IEventEmitterMap_1 = require("../../localEventEmitterMap/api/IEventEmitterMap"); /** * Abstract mediator implementation used by `SceneMediator` and `ViewMediator` classes. */ var AbstractMediator = /** @class */ (function () { function AbstractMediator() { } /** * Runs after the mediator has been destroyed. * Cleans up listeners mapped through the local EventEmitterMap. */ AbstractMediator.prototype.postDestroy = function () { this._eventEmitterMap.unmapListeners(); }; /*============================================================================*/ /* Protected Functions */ /*============================================================================*/ /** * Use this method to listen for events dispatched by the `Phaser.Events.EventEmitter`. * All the registered listeners will be automatically removed when this mediator is destroyed. * * Call this method is the same as calling `on` or `addListener` directly on the * `Phaser.Events.EventEmitter`, but keeps a list of listeners for easy (usually automatic) removal. * * The `context` will be automatically mapped to `this` when no context information is provided. * * @param emitter The `Phaser.Events.EventEmitter` to listen to * @param event The `event` type to listen for * @param listener The `event` handler * @param context The listener function's "this" */ AbstractMediator.prototype.on = function (emitter, event, listener, context) { this._eventEmitterMap.on(emitter, event, listener, context || this); }; /** * Use this method to listen for events dispatched by the `Phaser.Events.EventEmitter`. * All the registered listeners will be automatically removed when this mediator is destroyed. * * Call this method is the same as calling `once` directly on the * `Phaser.Events.EventEmitter`, but keeps a list of listeners for easy (usually automatic) removal. * * The `context` will be automatically mapped to `this` when no context information is provided. * * @param emitter The `Phaser.Events.EventEmitter` to listen to * @param event The `event` type to listen for * @param listener The `event` handler * @param context The listener function's "this" */ AbstractMediator.prototype.once = function (emitter, event, listener, context) { this._eventEmitterMap.once(emitter, event, listener, context || this); }; /** * Use this method to remove listeners from events dispatched by the `Phaser.Events.EventEmitter`. * * Call this method is the same as calling `off` directly on the * `Phaser.Events.EventEmitter` emitter, but updates our local list of listeners. * * The `context` will be automatically mapped to `this` when no context information is provided. * * @param emitter The `Phaser.Events.EventEmitter` to listen to * @param event The `event` type to listen for * @param listener The `event` handler * @param contextt The listener function's "this" */ AbstractMediator.prototype.off = function (emitter, event, listener, context) { this._eventEmitterMap.off(emitter, event, listener, context || this); }; /** * Use this method to listen for events dispatched by the `EventDispatcher/code> provided by RobotlegsJS core. * * Call this method is the same as calling `addEventListener` directly on the * `EventDispatcher`, but keeps a list of listeners for easy (usually automatic) removal. * * The `context` will be automatically set to `this` when no context information is provided. * * @param event The `event` type to listen for * @param listener The `event` handler * @param context The listener function's "this" * @param eventClass Optional Event class for a stronger mapping. * @param useCapture Determines whether the listener works in the capture phase or the bubbling phases. * @param priority The priority level of the event listener. */ AbstractMediator.prototype.addContextListener = function (event, listener, context, eventClass, useCapture, priority) { this._eventEmitterMap.mapListener(this._eventDispatcher, event, listener, context || this, eventClass, useCapture, priority); }; /** * Use this method to remove listeners from events dispatched by the `EventDispatcher/code> provided by RobotlegsJS core. * * Call this method is the same as calling `removeEventListener` directly on the * `EventDispatcher`, but updates our local list of listeners. * * The `context` will be automatically set to `this` when no context information is provided. * * @param event The `event` type to listen for * @param listener The `event` handler * @param context The listener function's "this" * @param eventClass Optional Event class for a stronger mapping. * @param useCapture Determines whether the listener works in the capture phase or the bubbling phases. * @param priority The priority level of the event listener. */ AbstractMediator.prototype.removeContextListener = function (event, listener, context, eventClass, useCapture) { this._eventEmitterMap.unmapListener(this._eventDispatcher, event, listener, context || this, eventClass, useCapture); }; /** * Use this method to listen for DOM events dispatched by the provided `EventTarget/code>. * * Call this method is the same as calling `addEventListener` directly on the * `EventTarget`, but keeps a list of listeners for easy (usually automatic) removal. * * @param eventTarget The `EventTarget` to listen to * @param event The `Event` type to listen for * @param listener The `Event` handler * @param options An options object that specifies characteristics about the event listener */ AbstractMediator.prototype.addDomListener = function (eventTarget, event, listener, options) { this._eventEmitterMap.mapDomListener(eventTarget, event, listener, options); }; /** * Use this method to remove listeners from DOM events dispatched by the provided `EventTarget/code>. * * Call this method is the same as calling `removeEventListener` directly on the * `EventTarget`, but updates our local list of listeners. * * @param dispatcher The `EventTarget` * @param event The `Event` type * @param listener The `Event` handler * @param options An options object that specifies characteristics about the event listener */ AbstractMediator.prototype.removeDomListener = function (eventTarget, event, listener) { this._eventEmitterMap.unmapDomListener(eventTarget, event, listener); }; /** * Use this method to dispatch events to the Robotlegs context through the `EventDispatcher/code> provided by RobotlegsJS core. * * Call this method to trigger the execution of commands, call external services or communicate with other mediators. * * @param event The `Event` to dispatch */ AbstractMediator.prototype.dispatch = function (event) { this._eventDispatcher.dispatchEvent(event); }; tslib_1.__decorate([ core_1.inject(IEventEmitterMap_1.IEventEmitterMap), tslib_1.__metadata("design:type", Object) ], AbstractMediator.prototype, "_eventEmitterMap", void 0); tslib_1.__decorate([ core_1.inject(core_1.IEventDispatcher), tslib_1.__metadata("design:type", Object) ], AbstractMediator.prototype, "_eventDispatcher", void 0); AbstractMediator = tslib_1.__decorate([ core_1.injectable() ], AbstractMediator); return AbstractMediator; }()); exports.AbstractMediator = AbstractMediator; //# sourceMappingURL=AbstractMediator.js.map