tlojs
Version:
The Last One - The last npm package you'll need to install
29 lines (28 loc) • 1.15 kB
JavaScript
;
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Injector = exports.Injectable = void 0;
require("reflect-metadata");
var Injectable = function () {
return function (target) {
// do something with `target`, e.g. some kind of validation or passing it to the Injector and store them
};
};
exports.Injectable = Injectable;
exports.Injector = new /** @class */ (function () {
function class_1() {
}
// resolving instances
class_1.prototype.resolve = function (target) {
// tokens are required dependencies, while injections are resolved tokens from the Injector
var tokens = Reflect.getMetadata('design:paramtypes', target) || [];
var injections = tokens.map(function (token) { return exports.Injector.resolve(token); });
var instance = new (target.bind.apply(target, __spreadArray([void 0], injections)))();
return instance;
};
return class_1;
}());