@robotlegsjs/core
Version:
An architecture-based IoC framework for JavaScript/TypeScript
53 lines • 2.9 kB
JavaScript
;
// ------------------------------------------------------------------------------
// 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.EventDispatcherExtension = void 0;
var IEventDispatcher_1 = require("../../events/api/IEventDispatcher");
var EventDispatcher_1 = require("../../events/impl/EventDispatcher");
var LifecycleEventRelay_1 = require("./impl/LifecycleEventRelay");
/**
* This extension maps an IEventDispatcher into a context's injector.
*/
var EventDispatcherExtension = /** @class */ (function () {
/*============================================================================*/
/* Constructor */
/*============================================================================*/
/**
* Creates an Event Dispatcher Extension
*
* @param eventDispatcher Optional IEventDispatcher instance to share
*/
function EventDispatcherExtension(eventDispatcher) {
if (eventDispatcher === void 0) { eventDispatcher = null; }
this._eventDispatcher = eventDispatcher || new EventDispatcher_1.EventDispatcher();
}
/*============================================================================*/
/* Public Functions */
/*============================================================================*/
/**
* @inheritDoc
*/
EventDispatcherExtension.prototype.extend = function (context) {
this._context = context;
this._context.injector.bind(IEventDispatcher_1.IEventDispatcher).toConstantValue(this._eventDispatcher);
this._context.beforeInitializing(this._configureLifecycleEventRelay.bind(this));
this._context.afterDestroying(this._destroyLifecycleEventRelay.bind(this));
};
/*============================================================================*/
/* Private Functions */
/*============================================================================*/
EventDispatcherExtension.prototype._configureLifecycleEventRelay = function () {
this._lifecycleRelay = new LifecycleEventRelay_1.LifecycleEventRelay(this._context, this._eventDispatcher);
};
EventDispatcherExtension.prototype._destroyLifecycleEventRelay = function () {
this._lifecycleRelay.destroy();
};
return EventDispatcherExtension;
}());
exports.EventDispatcherExtension = EventDispatcherExtension;
//# sourceMappingURL=EventDispatcherExtension.js.map