-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Update plugin-proposal-decorators.md #1914
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
base: main
Are you sure you want to change the base?
Conversation
Examples writen in old proposal syntax should be updated since Babel 7.1.0 finally supports the new decorators proposal.
Deploy preview for babel ready! Built with commit 3533978 |
docs/plugin-proposal-decorators.md
Outdated
class MyClass { } | ||
@defineElement('num-counter') | ||
class Counter extends HTMLElement { | ||
@observed #x = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't support decorator and private elements in the same class yet.
Could you just convert the old examples to the new proposal and add a link to the proposal "for further examples"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
descriptor: { | ||
...elementDescriptor.descriptor, | ||
enumerable: value | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this function can be simplified to
return function(elementDescriptor) {
elementDescriptor.descriptor.enumerable = value;
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed the examples of the latest proposal were wrote in immutable style. But it looks like not necessary.
So the others can also be simplified to
function annotation(classDescriptor) {
classDescriptor.elements.push({
kind: 'field',
key: 'annotated',
placement: 'static',
descriptor: {},
initializer: () => true,
});
}
function isTestable(value) {
return function(classDescriptor) {
classDescriptor.elements.push({
kind: 'field',
key: 'isTestable',
placement: 'static',
descriptor: {},
initializer: () => value,
});
};
}
It works in Babel 7.1.0. However, the proposal said a decorator function returns a decorator. So should I add a return ?
return function(elementDescriptor) {
elementDescriptor.descriptor.enumerable = value;
return elementDescriptor
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a decorator returns nothing, it returns the original descriptor (probably that introduction needs to be updated, in you want to open a PR).
I'd like to have examples in both styles, to show different ways of using decorators.
Examples writen in old proposal syntax should be updated since Babel 7.1.0 finally supports the new decorators proposal.