-
Notifications
You must be signed in to change notification settings - Fork 431
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
Feedback for ES decorator proposal #223
Comments
Disclaimer: I'm not familiar with the latest decorator spec yet and vue-class-component still use stage 1 decorator, so the following may not be applicable on the current spec. TL;DR @Component
class MyComp extends Vue {
@Prop foo;
} The major difference between ES (babel legacy decorator) and TS decorators (--experimentalDecorators) is the behavior of class property initialization when there is no initializer. for example: // Define Vue component
@Component
class MyComp extends Vue {
// Define component props
// props are passed from a parent component, (e.g. <MyComp :foo="'some value'" />)
// so we should not initialize its value here.
@Prop foo;
} On the above code, ES decorator initializes Case 1: Component prop unexpectedly overwritten with
|
Looks like the latest decorator proposal is quite different from the earlier version (and the one TS is currently using). The latest proposal gives more meta-programming capabilities and after looking into it, I'm pretty happy about it. Specifically there are improvements that can help with the problems we currently see in
Question for @DanielRosenwasser: does TS have the goal to update/align decorators semantics with latest ES proposal once it's stabilized? |
Yes, we intend to align once the proposal stabilizes. |
This helps decorator library very much. Currently we have to execute class constructor to collect class elements. So we have to bother to distinguish undefined/uninitialized properties. With the new API I don't think it is necessary any more. @ktsn :) However performance might still be a concern. With the new API, the new component decorator can be written as something like: function Component(classDescriptor) {
let {kind, elements} = classDescriptor;
assert(kind == "class");
// closure here
let data = () => {
const d = {}
for (const element of elements) {
collectData(element, d)
}
}
return {
kind,
//elements, // elements are included in Vue
finisher(klass) { return findSuper(klass).extend({ data })} // findSuper(klass) should be a Vue class
}
} One Closure is almost unavoidable. I wonder if we can change the implementation via Other than implementation, I wish decorator can help us make Vue class more declarative. For example, decorators can provide a place to explicitly declare what events one component can emit. btw, |
Using vue-property-decorators, I would really like to see |
@mattheiler I think When I tried to implement that feature, we needed to initialize the original class in multiple times because it is the only way we can collect property values and it may introduce unexpected behavior if the property initializer has some side effects. On the current decorator, we can collect them via each property's |
Afraid to sound stupid, but after almost two years I'm still not getting the real value of decorators. I must agree with @carlsmith coffeescript6/discuss#9 (comment) that decorators are just a fancier way to write wrappers. And it even doesn't look natural in JavaScript, since it would be the only operator (probably, alongside the It just looks ripped off from Python and alienly slapped on syntax with quite different philisophy. In worst scenario it should be something like @Component() {
Class Test {
// ....
}
} |
In case anyone is interested in this,
@Component
class MyComponent extends Vue {
reactiveVar = undefined
reactiveVar2
}
@Component
class MyComponent extends Vue {
@Prop({type: String}) myProp = 'default value!'
} (Requires, obviously, the babel plugin for decorators, specifying |
@yotamofek your implementation seems pretty cool on first look. Don't know much about stage 2 decorators so I can't comment more than that. I'm interested though in what you mean by 'non-optimal implementation'. On the first look, your code seems to be just a simple wrapper of the existing |
Well, my assumption that it is non-optimal is as naive as my implementation itself. :) |
Hey @wycats - so, I've been playing around a little more with "porting" this library to use stage-2 decorators, and I might have a few pairs of cents to give on the standard. So, two things that I think can be improved in the standard:
|
@ktsn |
@yotamofek @Mikilll94 I've been working with @littledan, @pzuraq and the TC39 JavaScript Frameworks outreach group on a new draft of the decorators proposal. So far the initial responses have been positive and I hope we have something reviewable soon. |
I've been contacted by @wycats (who is the champion of the ES decorator proposal at TC39) to provide feedback for the proposal from framework authors' perspective, and since this library (and
vue-property-decorators
) is the primary use case where Vue leverages decorators, I'm hosting the thread here.I know there are a few discrepancies between ES and TS decorators, but am not 100% clear on the details. Ideally, I hope we can use
vue-class-component
andvue-property-decorators
in both ES and TS contexts.Would appreciate thoughts from @ktsn and @kaorun343 on this topic.
The text was updated successfully, but these errors were encountered: