diff --git a/projects/ngze/control-value-transformer/src/lib/control-value-transformer.module.ts b/projects/ngze/control-value-transformer/src/lib/control-value-transformer.module.ts index fef5954..ee2336c 100644 --- a/projects/ngze/control-value-transformer/src/lib/control-value-transformer.module.ts +++ b/projects/ngze/control-value-transformer/src/lib/control-value-transformer.module.ts @@ -8,7 +8,7 @@ import { Transformer } from './shared'; /** * Injection token that used to run {@link registerControlValueTransformers}. */ -export const REGISTER_CONTROL_VALUE_TRANSFORMERS = new InjectionToken('REGISTER_CONTROL_VALUE_TRANSFORMERS'); +export const REGISTER_CONTROL_VALUE_TRANSFORMERS = new InjectionToken('REGISTER_CONTROL_VALUE_TRANSFORMERS'); /** * Registration factory for new control value transformers. @@ -52,5 +52,5 @@ export class ControlValueTransformerModule { }; } - constructor(@Optional() @Inject(REGISTER_CONTROL_VALUE_TRANSFORMERS) registerControlValueTransformers: void) {} + constructor(@Optional() @Inject(REGISTER_CONTROL_VALUE_TRANSFORMERS) registerControlValueTransformers) {} } diff --git a/projects/ngze/control-value-transformer/src/lib/metadata/control-value-transformer-metadata.utils.ts b/projects/ngze/control-value-transformer/src/lib/metadata/control-value-transformer-metadata.utils.ts index b7707e0..4938717 100644 --- a/projects/ngze/control-value-transformer/src/lib/metadata/control-value-transformer-metadata.utils.ts +++ b/projects/ngze/control-value-transformer/src/lib/metadata/control-value-transformer-metadata.utils.ts @@ -9,14 +9,21 @@ import { ControlValueTransformerMetadata } from './control-value-transformer-met */ const CONTROL_VALUE_TRANSFORMER_METADATA = Symbol('CONTROL_VALUE_TRANSFORMER_METADATA'); +/** + * Returns metadata property descriptor associate with the given control value transformer. + * @param transformer - Instance of control value transformer that should be decorated. + * @returns Transformer metadata property descriptor. + */ +const getTransformerMetadataPropertyDescriptor = (transformer: Transformer) => { + return Object.getOwnPropertyDescriptor(transformer.constructor, CONTROL_VALUE_TRANSFORMER_METADATA); +}; + /** * Asserts the given transformer class is decorated with {@link Transformer}. * @param transformer - Instance of control value transformer that should be decorated. */ const assertTransformerIsDecorated = (transformer: Transformer) => { - const hasMetadata = Reflect.hasMetadata(CONTROL_VALUE_TRANSFORMER_METADATA, transformer.constructor); - - if (!hasMetadata) { + if (!getTransformerMetadataPropertyDescriptor(transformer)) { throw new TypeError(`"${transformer.constructor}" is not decorated with ControlValueTransformer.`); } }; @@ -28,8 +35,8 @@ const assertTransformerIsDecorated = (transformer: Transformer) => { */ export const getControlValueTransformerMetadata = (transformer: Transformer): ControlValueTransformerMetadata => { assertTransformerIsDecorated(transformer); - - return Reflect.getMetadata(CONTROL_VALUE_TRANSFORMER_METADATA, transformer.constructor); + const metadataPropertyDescriptor = getTransformerMetadataPropertyDescriptor(transformer); + return metadataPropertyDescriptor.value; }; /** @@ -41,5 +48,7 @@ export const definedControlValueTransformerMetadata = ( transformerClass: Class, metadata: ControlValueTransformerMetadata ) => { - return Reflect.defineMetadata(CONTROL_VALUE_TRANSFORMER_METADATA, metadata, transformerClass); + return Object.defineProperty(transformerClass, CONTROL_VALUE_TRANSFORMER_METADATA, { + value: metadata, + }); }; diff --git a/projects/ngze/control-value-transformer/src/public-api.ts b/projects/ngze/control-value-transformer/src/public-api.ts index de58827..5057c36 100644 --- a/projects/ngze/control-value-transformer/src/public-api.ts +++ b/projects/ngze/control-value-transformer/src/public-api.ts @@ -2,8 +2,6 @@ * Public API Surface of Control Value Transformer */ -import 'reflect-metadata'; - export { ControlValueTransformer, ControlValueTransformerMetadata,