Update plugin-proposal-decorators.md#1914
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.
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"?
| descriptor: { | ||
| ...elementDescriptor.descriptor, | ||
| enumerable: value | ||
| } |
There was a problem hiding this comment.
All this function can be simplified to
return function(elementDescriptor) {
elementDescriptor.descriptor.enumerable = value;
};There was a problem hiding this comment.
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.
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.