Commit e3acddce authored by nanahira's avatar nanahira

fix class problem

parent 607cc006
...@@ -37,10 +37,17 @@ export class Reflector<M extends StringDict, AM extends StringDict> { ...@@ -37,10 +37,17 @@ export class Reflector<M extends StringDict, AM extends StringDict> {
metadataKey: K, metadataKey: K,
instance: I, instance: I,
key: keyof I & (string | symbol), key: keyof I & (string | symbol),
alternate: any = instance, alternate: any,
): ArrayValue<AM, K> { ): ArrayValue<AM, K> {
const valueFromClass = this.getArray(metadataKey, alternate); const valueFromClass = this.getArray(metadataKey, instance);
const valueFromAlternate = alternate
? this.getArray(metadataKey, alternate)
: [];
const valueFromProperty = this.getArray(metadataKey, instance, key); const valueFromProperty = this.getArray(metadataKey, instance, key);
return [...valueFromClass, ...valueFromProperty] as ArrayValue<AM, K>; return [
...valueFromClass,
...valueFromAlternate,
...valueFromProperty,
] as ArrayValue<AM, K>;
} }
} }
...@@ -10,11 +10,10 @@ export class MetadataSetter<M extends StringDict, AM extends StringDict> { ...@@ -10,11 +10,10 @@ export class MetadataSetter<M extends StringDict, AM extends StringDict> {
K extends MergeKey<M, AM>, K extends MergeKey<M, AM>,
GM extends Record<MergeKey<M, AM>, any> = GenericMap<M, AM> GM extends Record<MergeKey<M, AM>, any> = GenericMap<M, AM>
>(metaKey: K, target: any, key?: any): GM[K] { >(metaKey: K, target: any, key?: any): GM[K] {
const targetClass = target.constructor;
if (key) { if (key) {
return Reflect.getMetadata(metaKey, targetClass, key); return Reflect.getMetadata(metaKey, target, key);
} else { } else {
return Reflect.getMetadata(metaKey, targetClass); return Reflect.getMetadata(metaKey, target);
} }
} }
...@@ -22,11 +21,10 @@ export class MetadataSetter<M extends StringDict, AM extends StringDict> { ...@@ -22,11 +21,10 @@ export class MetadataSetter<M extends StringDict, AM extends StringDict> {
K extends MergeKey<M, AM>, K extends MergeKey<M, AM>,
GM extends Record<MergeKey<M, AM>, any> = GenericMap<M, AM> GM extends Record<MergeKey<M, AM>, any> = GenericMap<M, AM>
>(metaKey: K, value: GM[K], target: any, key?: any) { >(metaKey: K, value: GM[K], target: any, key?: any) {
const targetClass = target.constructor;
if (key) { if (key) {
return Reflect.defineMetadata(metaKey, value, targetClass, key); return Reflect.defineMetadata(metaKey, value, target, key);
} else { } else {
return Reflect.defineMetadata(metaKey, value, targetClass); return Reflect.defineMetadata(metaKey, value, target);
} }
} }
...@@ -40,16 +38,17 @@ export class MetadataSetter<M extends StringDict, AM extends StringDict> { ...@@ -40,16 +38,17 @@ export class MetadataSetter<M extends StringDict, AM extends StringDict> {
keysIndexMeta?: IK, keysIndexMeta?: IK,
): AllDecorators { ): AllDecorators {
return (target: any, key?: any, descriptor?: any) => { return (target: any, key?: any, descriptor?: any) => {
const targetClass = !key && !descriptor ? target : target.constructor;
const oldValue = this.getMetadataInDecorator<K, GM>( const oldValue = this.getMetadataInDecorator<K, GM>(
metadataKey, metadataKey,
target, targetClass,
key, key,
); );
const newValue = metadataValueFun(oldValue); const newValue = metadataValueFun(oldValue);
this.setMetadataInDecorator(metadataKey, newValue, target, key); this.setMetadataInDecorator(metadataKey, newValue, targetClass, key);
if (keysIndexMeta) { if (keysIndexMeta) {
const keysDec = this.append<IK, any>(keysIndexMeta, key); const keysDec = this.append<IK, any>(keysIndexMeta, key);
keysDec(target); keysDec(targetClass);
} }
if (descriptor) { if (descriptor) {
return descriptor; return descriptor;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment