Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(metadata): targetKey in Reflect.defineMetadata is optional #33

Merged
merged 1 commit into from
May 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ interface MetadataType {
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
get(metadataKey: string, target: Function, targetKey: string): Object;
get(metadataKey: string, target: Function, targetKey?: string): Object;
/**
* Gets metadata specified by a key on a target, only searching the own instance.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
getOwn(metadataKey: string, target: Function, targetKey: string): Object;
getOwn(metadataKey: string, target: Function, targetKey?: string): Object;
/**
* Defines metadata specified by a key on a target.
* @param metadataKey The key for the metadata to define.
* @param target The target to set the metadata on.
* @param targetKey The member on the target to set the metadata on.
*/
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void;
define(metadataKey: string, metadataValue: Object, target: Function, targetKey?: string): void;
/**
* Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found.
* @param metadataKey The key for the metadata to lookup or create.
* @param Type The type of metadata to create if existing metadata is not found.
* @param target The target to lookup or create the metadata on.
* @param targetKey The member on the target to lookup or create the metadata on.
*/
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object;
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey?: string): Object;
}

/**
Expand All @@ -52,19 +52,19 @@ export const metadata: MetadataType = {
resource: 'aurelia:resource',
paramTypes: 'design:paramtypes',
properties: 'design:properties',
get(metadataKey: string, target: Function, targetKey: string): Object {
get(metadataKey: string, target: Function, targetKey?: string): Object {
if (!target) { return undefined; }
let result = metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
},
getOwn(metadataKey: string, target: Function, targetKey: string): Object {
getOwn(metadataKey: string, target: Function, targetKey?: string): Object {
if (!target) { return undefined; }
return Reflect.getOwnMetadata(metadataKey, target, targetKey);
},
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void {
define(metadataKey: string, metadataValue: Object, target: Function, targetKey?: string): void {
Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey);
},
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object {
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey?: string): Object {
let result = metadata.getOwn(metadataKey, target, targetKey);

if (result === undefined) {
Expand Down