Skip to content

Commit

Permalink
Merge pull request #5 from abraham/refactors
Browse files Browse the repository at this point in the history
Remove unneeded ordinaryHasOwnMetadata  method
  • Loading branch information
abraham authored Jul 24, 2018
2 parents dc651db + 437cf82 commit c53f22d
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function getOwnMetadata(metadataKey: MetadataKey, target: Target, propert
}

export function hasOwnMetadata(metadataKey: MetadataKey, target: Target, propertyKey?: PropertyKey): boolean {
return ordinaryHasOwnMetadata(metadataKey, target, propertyKey);
return !!ordinaryGetOwnMetadata(metadataKey, target, propertyKey);
}

function decorateConstructor(decorators: ClassDecorator[], target: Function): Function {
Expand All @@ -63,10 +63,7 @@ function decorateConstructor(decorators: ClassDecorator[], target: Function): Fu

function decorateProperty(decorators: MemberDecorator[], target: Target, propertyKey: PropertyKey, descriptor?: PropertyDescriptor): PropertyDescriptor | undefined {
decorators.reverse().forEach((decorator: MemberDecorator) => {
const decorated = decorator(target, propertyKey, descriptor);
if (decorated) {
descriptor = decorated;
}
descriptor = decorator(target, propertyKey, descriptor) || descriptor;
});
return descriptor;
}
Expand All @@ -79,18 +76,13 @@ function ordinaryDefineOwnMetadata(metadataKey: MetadataKey, metadataValue: Meta
}

function ordinaryGetMetadata(metadataKey: MetadataKey, target: Target, propertyKey?: PropertyKey): Function | undefined {
return ordinaryHasOwnMetadata(metadataKey, target, propertyKey)
return !!ordinaryGetOwnMetadata(metadataKey, target, propertyKey)
? ordinaryGetOwnMetadata(metadataKey, target, propertyKey)
: Object.getPrototypeOf(target)
? ordinaryGetMetadata(metadataKey, Object.getPrototypeOf(target), propertyKey)
: undefined;
}

function ordinaryHasOwnMetadata(metadataKey: MetadataKey, target: Target, propertyKey?: PropertyKey): boolean {
const metadataMap = getMetadataMap(target, propertyKey);
return !!metadataMap && !!metadataMap.has(metadataKey);
}

function ordinaryGetOwnMetadata(metadataKey: MetadataKey, target: Target, propertyKey?: PropertyKey): Function | undefined {
if (target === undefined) throw new TypeError();
const metadataMap = getMetadataMap(target, propertyKey);
Expand Down

0 comments on commit c53f22d

Please sign in to comment.