UNPKG

mana-syringe

Version:

IoC library for mana, easily to use.

118 lines (92 loc) 3.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SyringeModule = void 0; exports.isSyringeModule = isSyringeModule; var _core = require("../core"); var _contributionRegister = require("../contribution/contribution-register"); var _inversify = require("inversify"); var _register = require("../register"); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } var SyringeModule = /*#__PURE__*/function () { /** * @readonly * module unique id */ function SyringeModule(registry) { var _this = this; _classCallCheck(this, SyringeModule); this.id = void 0; this.inversifyModule = void 0; this.baseRegistry = void 0; this.optionCollection = void 0; this.inversifyRegister = function (bind, unbind, isBound, rebind) { var inversifyRegister = { bind: bind, unbind: unbind, isBound: isBound, rebind: rebind }; var register = function register(token) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (_core.Utils.isInjectOption(token)) { _register.Register.resolveOption(inversifyRegister, token); } else { _register.Register.resolveTarget(inversifyRegister, token, options); } }; if (_this.baseRegistry) { _this.baseRegistry(register); } if (_this.optionCollection) { _this.optionCollection.forEach(function (option) { return register(option); }); } }; this.baseRegistry = registry; this.inversifyModule = new _inversify.ContainerModule(this.inversifyRegister); this.id = this.inversifyModule.id; } _createClass(SyringeModule, [{ key: "options", get: function get() { if (!this.optionCollection) { this.optionCollection = []; } return this.optionCollection; } }, { key: "register", value: function register() { var _this2 = this; for (var _len = arguments.length, options = new Array(_len), _key = 0; _key < _len; _key++) { options[_key] = arguments[_key]; } options.forEach(function (option) { return _this2.options.push(option); }); return this; } }, { key: "contribution", value: function contribution() { var _this3 = this; for (var _len2 = arguments.length, tokens = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { tokens[_key2] = arguments[_key2]; } tokens.forEach(function (token) { return _this3.options.push((0, _contributionRegister.contributionInjectOption)(token)); }); return this; } }]); return SyringeModule; }(); exports.SyringeModule = SyringeModule; function isSyringeModule(data) { return data && 'inversifyModule' in data; }