TC39 Decorator Metadata
In relation to the Decorator Metadata proposal, this decorator "mimics" a similar behaviour as the one defined by the proposal. Defining and retrieving metadata relies on a decorator's context.metadata object, and the Symbol.metadata property of a class.
Example:
import { meta, getMeta } from '@aedart/support/meta';
@meta('service_alias', 'locationSearcher')
class Service {}
getMeta(Service, 'service_alias'); // locationSearcher
Roughly "desugars" to the following:
function meta(key, value) {
return (target, context) => {
context.metadata[key] = value;
}
}
@meta('service_alias', 'locationSearcher')
class Service {}
Service[Symbol.metadata].service_alias; // locationSearcher
(Above shown example is very simplified. Actual implementation is a bit more complex...)
At present, the internal mechanisms of the meta decorator must rely on a WeakMap to associate metadata with the intended class. When the Decorator Metadata proposal becomes more mature and transpilers offer the context.metadata object (or when browsers support it), then this decorator will be updated respectfully to use the available metadata object.