elmer-ui-core
Version:
web app framework
69 lines (68 loc) • 3.23 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InjectModel = void 0;
var elmer_common_1 = require("elmer-common");
var inject_1 = require("../inject");
var InjectModel = (function (_super) {
__extends(InjectModel, _super);
function InjectModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
InjectModel.prototype.inject = function (target, models, propertyKey, isAutowired) {
var _this = this;
if (typeof propertyKey === "string" && propertyKey.length > 0) {
if (!target[propertyKey]) {
target[propertyKey] = {};
}
}
if (target && models && Object.keys(models).length > 0) {
Object.keys(models).map(function (tmpKey) {
if (!_this.isEmpty(tmpKey)) {
var tmpFactory = models[tmpKey];
if (typeof tmpFactory === "function") {
var tmpObj = !isAutowired ? (new tmpFactory(target)) : inject_1.globalClassFactory(tmpFactory);
if (!_this.isEmpty(propertyKey)) {
target[propertyKey][tmpKey] = tmpObj;
}
else {
target[tmpKey] = tmpObj;
}
}
else {
console.log(target.className, models);
throw new Error(tmpKey + "注入对象不是function");
}
}
else {
throw new Error("注入模块必须设置propertyKey");
}
});
}
};
InjectModel = __decorate([
inject_1.Injectable("InjectModel")
], InjectModel);
return InjectModel;
}(elmer_common_1.Common));
exports.InjectModel = InjectModel;