@keenondrums/metadata-utils
v1.0.1
Published
Convenience utils for reflected metadata
Downloads
3
Readme
metadata-utils
Convenience utils for reflected metadata.
Installation
Run
npm i @keenondrums/metadata-utils reflect-metadata
Add
import 'reflect-metadata'
to the root of your application
API
getMetadataAndCache
Gets metadata from the prototype (using Relect.getMetadata) and sets it as own metadata. Useful to enhance performance for retrieving metadata from ancestors. Has the same signature as Relect.getMetadata.
import 'reflect-metadata'
import { getMetadataAndCache } from '@keenondrums/metadata-utils'
class Parent {}
Reflect.defineMetadata('key', 'value', Parent)
Reflect.getOwnMetadata('key', Parent) // returns 'value'
getMetadataAndCache('key', Parent) // returns 'value', basically calls Reflect.getOwnMetadata under the hood and does nothing else in this case
class Child extends Parent {}
Reflect.getOwnMetadata('key', Child) // returns `undefined` as Child doesn't have any own metadata for 'key'
getMetadataAndCache('key', Child) // returns 'value' from Parent and set it as own metadata
Reflect.getOwnMetadata('key', Child) // now it returns 'value'