tc39 / proposal-decorators

Decorators for ES6 classes
https://arai-a.github.io/ecma262-compare/?pr=2417
2.69k stars 108 forks source link

Inline decorator syntax #49

Open littledan opened 6 years ago

littledan commented 6 years ago

Previous discussion: https://github.com/tc39/proposal-decorators-previous/issues/22

OK to leave for v2?

bmeck commented 6 years ago

I'd would prefer to leave it for a follow on.

trusktr commented 3 weeks ago

Maybe this can be closed unless there's a clear benefit. We can avoid designing class decorators in such a way as the linked issue.

For example, instead of something like this (coughAngularcough):

@component({
  props: {
    foo: Number,
  },
  template: html`
     <div>100 lines of HTML. {{foo}}</div>
  `
})
class MyComponent extends Component {} // why does this empty class even exist?

design it in a more semantic way:

class MyComponent extends Component {
  @numberAttribute accessor foo = 123

  template = () => html`
     <div>100 lines of HTML. ${this.foo}</div>
  `
}

Here's a real-world example: