Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
autoRegister(fn: any, key?: any): void {
let registration;
if (fn === null || fn === undefined) {
throw new Error(badKeyError);
}
if (typeof fn === 'function') {
registration = Metadata.get(Metadata.registration, fn);
if (registration !== undefined) {
registration.register(this, key || fn, fn);
} else {
this.registerSingleton(key || fn, fn);
}
} else {
this.registerInstance(fn, fn);
}
}
constructor(key, exportedValue, resourceTypeMeta?){
if(!resourceTypeMeta){
resourceTypeMeta = Metadata.get(Metadata.resource, exportedValue);
if(!resourceTypeMeta){
resourceTypeMeta = new HtmlBehaviorResource();
resourceTypeMeta.elementName = hyphenate(key);
Reflect.defineMetadata(Metadata.resource, resourceTypeMeta, exportedValue);
}
}
if(resourceTypeMeta instanceof HtmlBehaviorResource){
if(resourceTypeMeta.elementName === undefined){
//customeElement()
resourceTypeMeta.elementName = hyphenate(key);
} else if(resourceTypeMeta.attributeName === undefined){
//customAttribute()
resourceTypeMeta.attributeName = hyphenate(key);
} else if(resourceTypeMeta.attributeName === null && resourceTypeMeta.elementName === null){
return resourceModule;
}
resourceModule = new ResourceModule(moduleId);
this.cache[moduleId] = resourceModule;
if (typeof moduleInstance === 'function') {
moduleInstance = { 'default': moduleInstance };
}
if (viewModelMember) {
mainResource = new ResourceDescription(viewModelMember, moduleInstance[viewModelMember]);
}
for (key in moduleInstance) {
exportedValue = moduleInstance[key];
if (key === viewModelMember || typeof exportedValue !== 'function') {
continue;
}
resourceTypeMeta = Metadata.get(Metadata.resource, exportedValue);
if (resourceTypeMeta) {
if (resourceTypeMeta.attributeName === null && resourceTypeMeta.elementName === null) {
//no customeElement or customAttribute but behavior added by other metadata
HtmlBehaviorResource.convention(key, resourceTypeMeta);
}
if (resourceTypeMeta.attributeName === null && resourceTypeMeta.elementName === null) {
//no convention and no customeElement or customAttribute but behavior added by other metadata
resourceTypeMeta.elementName = hyphenate(key);
}
if (!mainResource && resourceTypeMeta instanceof HtmlBehaviorResource && resourceTypeMeta.elementName !== null) {
mainResource = new ResourceDescription(key, exportedValue, resourceTypeMeta);
}
else {
resources.push(new ResourceDescription(key, exportedValue, resourceTypeMeta));
}
}
autoRegister(fn, key) {
var registration;
if (fn === null || fn === undefined) {
throw new Error('fn cannot be null or undefined.');
}
registration = Metadata.get(Metadata.registration, fn);
if (registration !== undefined) {
registration.register(this, key || fn, fn);
}
else {
this.registerSingleton(key || fn, fn);
}
}
/**
autoRegister(fn : any, key? : any) : void {
var registration;
if (fn === null || fn === undefined){
throw new Error(badKeyError)
}
if(typeof fn === 'function'){
registration = Metadata.get(Metadata.registration, fn);
if(registration !== undefined){
registration.register(this, key || fn, fn);
}else{
this.registerSingleton(key || fn, fn);
}
}else{
this.registerInstance(fn, fn);
}
}
static getDefault(target){
var strategy, annotation;
if(typeof target !== 'function'){
target = target.constructor;
}
annotation = Origin.get(target);
strategy = Metadata.get(ViewStrategy.metadataKey, target);
if(!strategy){
if(!annotation){
throw AggregateError('Cannot determinte default view strategy for object.', target);
}
strategy = new ConventionalViewStrategy(annotation.moduleId);
}else if(annotation){
strategy.moduleId = annotation.moduleId;
}
return strategy;
}
}