-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is Metadata? #86
Comments
I think metadata can be used for runtime type check, likes io-ts and flow-runtime. |
@MuYunyun I was guessing. See flow-runtime document's annotate part https://github.com/codemix/flow-runtime/tree/master/packages/babel-plugin-flow-runtime#options They annotate the function with metadata: import t from 'flow-runtime';
const add = t.annotate(
(a, b) => a + b,
t.function(
t.param('a', t.number()),
t.param('b', t.number()),
t.return(t.number())
)
); |
the simply code of const Metadata = new WeakMap()
function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
metadataMap = new Map()
metadataMap.set(metadataKey, metadataValue)
targetMetadata = new Map()
targetMetadata.set(propertyKey, metadataMap)
Metadata.set(target, targetMetadata)
} the simply code of function getOwnMetadata(metadataKey, target, propertyKey) {
var targetMetadata = Metadata.get(target)
var metadataMap = targetMetadata.get(propertyKey)
return metadataMap.get(metadataKey)
} we can notice it use So the Metadata is a |
Can I ask what is metadata exactly? I haven't found anywhere any good description, only methods JsDoc.
According to Metadata Proposal you offer to add to any JS Object unreachable property [[Metadata]]. But anyone could read and write to it with specialized methods? Like 'defineMetadata', 'getOwnMetadata'? So it is more like getter/setter from OOP without direct access to property.
So I can make something like this to copy the behavior?
The text was updated successfully, but these errors were encountered: