SB-6.1-PRE
This commit is contained in:
1 parent
690169a409
commit
358a25f522
3760 files changed
+300059
-36
No files matched your search
+48
@@ -0,0 +1,48 @@
|
||||
import { POST_CONSTRUCT_ERROR } from "../constants/error_msgs";
|
||||
import { TargetTypeEnum } from "../constants/literal_types";
|
||||
import * as METADATA_KEY from "../constants/metadata_keys";
|
||||
function _injectProperties(instance, childRequests, resolveRequest) {
|
||||
var propertyInjectionsRequests = childRequests.filter(function (childRequest) {
|
||||
return (childRequest.target !== null &&
|
||||
childRequest.target.type === TargetTypeEnum.ClassProperty);
|
||||
});
|
||||
var propertyInjections = propertyInjectionsRequests.map(resolveRequest);
|
||||
propertyInjectionsRequests.forEach(function (r, index) {
|
||||
var propertyName = "";
|
||||
propertyName = r.target.name.value();
|
||||
var injection = propertyInjections[index];
|
||||
instance[propertyName] = injection;
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
function _createInstance(Func, injections) {
|
||||
return new (Func.bind.apply(Func, [void 0].concat(injections)))();
|
||||
}
|
||||
function _postConstruct(constr, result) {
|
||||
if (Reflect.hasMetadata(METADATA_KEY.POST_CONSTRUCT, constr)) {
|
||||
var data = Reflect.getMetadata(METADATA_KEY.POST_CONSTRUCT, constr);
|
||||
try {
|
||||
result[data.value]();
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(POST_CONSTRUCT_ERROR(constr.name, e.message));
|
||||
}
|
||||
}
|
||||
}
|
||||
function resolveInstance(constr, childRequests, resolveRequest) {
|
||||
var result = null;
|
||||
if (childRequests.length > 0) {
|
||||
var constructorInjectionsRequests = childRequests.filter(function (childRequest) {
|
||||
return (childRequest.target !== null && childRequest.target.type === TargetTypeEnum.ConstructorArgument);
|
||||
});
|
||||
var constructorInjections = constructorInjectionsRequests.map(resolveRequest);
|
||||
result = _createInstance(constr, constructorInjections);
|
||||
result = _injectProperties(result, childRequests, resolveRequest);
|
||||
}
|
||||
else {
|
||||
result = new constr();
|
||||
}
|
||||
_postConstruct(constr, result);
|
||||
return result;
|
||||
}
|
||||
export { resolveInstance };
|
||||
Reference in new issue
Block a user