inversify/InversifyJS

View on GitHub
src/annotation/property_event_decorator.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { Metadata } from '../planning/metadata';

function propertyEventDecorator(eventKey: string, errorMessage: string) {
  return () => {
    return (target: { constructor: NewableFunction; }, propertyKey: string) => {
      const metadata = new Metadata(eventKey, propertyKey);

      if (Reflect.hasOwnMetadata(eventKey, target.constructor)) {
        throw new Error(errorMessage);
      }
      Reflect.defineMetadata(eventKey, metadata, target.constructor);
    }
  }
}

export { propertyEventDecorator }