UNPKG

vulpes

Version:
80 lines (65 loc) 2.41 kB
"use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Helper base class * Helpers provide an easy interface with which to * attach to services to perform ancillary tasks. * @memberof module:Vulpes */ var Helper = function () { function Helper() { _classCallCheck(this, Helper); this._service = null; } /** * The attached service * @type {Service} * @readonly * @memberof Helper */ _createClass(Helper, [{ key: "attach", /** * Attach to a service * This will be called by a Service instance * @param {Service} service The service to attach to * @memberof Helper * @throws {Error} Throws if already attached to a service */ value: function attach(service) { if (this._service !== null) { throw new Error("Failed attaching to service: Already attached"); } this._service = service; } /** * Initialise the helper (only called if the helper is added BEFORE * service initialisation) * @memberof Helper * @returns {Promise} */ }, { key: "initialise", value: function initialise() { return Promise.resolve(); } /** * Shutdown the helper * This will be called by a Service instance * @memberof Helper */ }, { key: "shutdown", value: function shutdown() { this._service = null; } }, { key: "service", get: function get() { return this._service; } }]); return Helper; }(); module.exports = Helper;