UNPKG

@malagu/core

Version:
48 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createValueProperty = exports.applyValueDecorator = exports.parseValueOption = exports.Value = exports.VALUE = void 0; const inversify_1 = require("inversify"); const config_util_1 = require("../config/config-util"); const utils_1 = require("../utils"); exports.VALUE = Symbol('Value'); const Value = function (elOrOption) { return (target, targetKey, index) => { const option = parseValueOption(target, targetKey, index, elOrOption); applyValueDecorator(option, target, targetKey, index); }; }; exports.Value = Value; const defaultValueOption = { detached: false }; function parseValueOption(target, targetKey, index, elOrOption) { const option = utils_1.AnnotationUtil.getValueOrOption(elOrOption, 'el'); option.el = option.el || targetKey; return Object.assign(Object.assign({}, defaultValueOption), option); } exports.parseValueOption = parseValueOption; function applyValueDecorator(option, target, targetKey, index) { if (option.detached) { if (index !== undefined) { throw new Error(`The ${target.constructor.name} itself is not injected into the container, so the parameter injection of the constructor is not supported.`); } createValueProperty(option, target, targetKey); return; } const el = option.el; inversify_1.inject(exports.VALUE)(target, targetKey, index); inversify_1.named(el)(target, targetKey, index); return option; } exports.applyValueDecorator = applyValueDecorator; function createValueProperty(option, target, property) { Object.defineProperty(target, property, { enumerable: true, get() { const el = option.el; return config_util_1.ConfigUtil.get(el); } }); } exports.createValueProperty = createValueProperty; //# sourceMappingURL=value.js.map