1.0.14 • Published 3 years ago

reflect-metadata-util v1.0.14

Weekly downloads
53
License
ISC
Repository
-
Last release
3 years ago
yarn add reflect-metadata-util
import { getClassMetadata, getThisTypeMetadata, setThisTypeMetadata, setClassMetadata, IPropertyKey } from '..';


@Reflect.metadata('kkkk', 1111)
class C1
{
	constructor()
	{
		console.log(`constructor`);
		console.log(1, getClassMetadata('kkkk', this));
		console.log(2, getThisTypeMetadata('kkkk', this));

		console.log(3, getClassMetadata('kkkk', this, 'constructor'));
		console.log(4, getThisTypeMetadata('kkkk', this, 'constructor'));

		console.log(`---------------`);
	}

	@LOG
	@Reflect.metadata('kkkk', 2222)
	m1()
	{
		console.log(1, getClassMetadata('kkkk', this));
		console.log(2, getThisTypeMetadata('kkkk', this));

		console.log(3, getClassMetadata('kkkk', this, 'm1'));
		console.log(4, getThisTypeMetadata('kkkk', this, 'm1'));
	}
}

function LOG(target: any, propertyName: IPropertyKey, descriptor: TypedPropertyDescriptor<any>)
{
	const old = descriptor.value;
	descriptor.value = function (...argv: any)
	{
		console.log(propertyName);
		let ret = old.apply(this, argv)
		console.log(`---------------`);
		return ret;
	}
}

console.log(`C1`);

console.log(1, getClassMetadata('kkkk', C1));
console.log(2, getThisTypeMetadata('kkkk', C1));

console.log(3, getClassMetadata('kkkk', C1, 'm1'));
console.log(4, getThisTypeMetadata('kkkk', C1, 'm1'));

console.log(`---------------`);

(new C1).m1();
C1
1 1111
2 undefined
3 undefined
4 undefined
---------------
constructor
1 undefined
2 1111
3 undefined
4 undefined
---------------
m1
1 undefined
2 1111
3 2222
4 undefined
---------------
1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.3

5 years ago