UNPKG

@robotlegsjs/core

Version:

An architecture-based IoC framework for JavaScript/TypeScript

65 lines 2.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.Pin = void 0; var PinEvent_1 = require("../api/PinEvent"); /** * Pins objects in memory * * @private */ var Pin = /** @class */ (function () { /*============================================================================*/ /* Constructor */ /*============================================================================*/ /** * @private */ function Pin(dispatcher) { /*============================================================================*/ /* Private Properties */ /*============================================================================*/ this._instances = new Map(); this._dispatcher = dispatcher; } /*============================================================================*/ /* Public Functions */ /*============================================================================*/ /** * Pin an object in memory * * @param instance Instance to pin */ Pin.prototype.detain = function (instance) { if (!this._instances.get(instance)) { this._instances.set(instance, true); this._dispatcher.dispatchEvent(new PinEvent_1.PinEvent(PinEvent_1.PinEvent.DETAIN, instance)); } }; /** * Unpins an object * * @param instance Instance to unpin */ Pin.prototype.release = function (instance) { if (this._instances.get(instance)) { this._instances.delete(instance); this._dispatcher.dispatchEvent(new PinEvent_1.PinEvent(PinEvent_1.PinEvent.RELEASE, instance)); } }; /** * Removes all pins */ Pin.prototype.releaseAll = function () { var _this = this; this._instances.forEach(function (value, key) { return _this.release(key); }); }; return Pin; }()); exports.Pin = Pin; //# sourceMappingURL=Pin.js.map