Created
August 5, 2021 08:17
-
-
Save rmlzy/5701a3fa7d0ab1a67aa63226dea69e08 to your computer and use it in GitHub Desktop.
Fake reflect-metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Metadata = new WeakMap(); | |
function defineMetadata(key, value, target) { | |
if (!Metadata.get(target)) { | |
Metadata.set(target, new Map()); | |
} | |
const map = Metadata.get(target); | |
map.set(key, value); | |
} | |
function getMetadata(key, target) { | |
const map = Metadata.get(target); | |
return map ? map.get(key) : ''; | |
} | |
Object.defineProperty(Reflect, 'defineMetadata', { | |
configurable: true, | |
writable: true, | |
value: defineMetadata, | |
}); | |
Object.defineProperty(Reflect, 'getMetadata', { | |
configurable: true, | |
writable: true, | |
value: getMetadata, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment