Skip to content

Conversation

mountainmoon
Copy link

Examples writen in old proposal syntax should be updated since Babel 7.1.0 finally supports the new decorators proposal.

Examples writen in old proposal syntax should be updated since Babel 7.1.0 finally supports the new decorators proposal.
@babel-bot
Copy link
Contributor

babel-bot commented Dec 11, 2018

Deploy preview for babel ready!

Built with commit 3533978

https://deploy-preview-1914--babel.netlify.com

class MyClass { }
@defineElement('num-counter')
class Counter extends HTMLElement {
@observed #x = 0;
Copy link
Member

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"?

Copy link
Author

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
}
Copy link
Member

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;
};

Copy link
Author

@mountainmoon mountainmoon Dec 13, 2018

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
};

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants