proposal-decorator-metadata
proposal-decorator-metadata copied to clipboard
Does method replace/reuse break the basic use case?
Given this example from the readme:
const METADATA = new WeakMap();
function meta(value) {
return (_, context) => {
METADATA.set(context.metadataKey, value);
};
}
@meta('a')
class C {
@meta('b')
m() {}
}
METADATA.get(C[Symbol.metadata]); // 'a'
METADATA.get(C.m[Symbol.metadata]); // 'b'
Would this fall apart if another decorator was involved that also replaced the method with a function that it could also use for other replacements? For example something like...
const env = { inProd: true }
const NO_OP = () => {}
function noopInProd() {
if (env.inProd) {
return NO_OP
}
}
Which when used with the original example (with an additional method)
@meta('a')
class C {
@meta('b')
@noopInProd
m() {}
@meta('c')
@noopInProd
m2() {}
}
METADATA.get(C.m[Symbol.metadata]); // 'c'?
METADATA.get(C.m2[Symbol.metadata]); // 'c'?
Since these methods would now be the same function, wouldn't they give the same metadata? (Also, I assume the gets are supposed to be referring to the methods through C.prototype
rather than C
directly?)