-
Notifications
You must be signed in to change notification settings - Fork 434
Enable to collect inital class properties as vue instance data #29
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
Conversation
|
||
// proxy to each prop values | ||
const propKeys = Object.keys(vm.$options.props || {}) | ||
propKeys.forEach(key => { |
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 found this approach is problematic when users define new properties in custom beforeCreate
lifecycle hooks. Here it only collects props and custom properties get lost.
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.
Thanks for your review! I'm thinking this problem but maybe we can solve this by using vm
as the prototype for data
instead of Component.prototype
?
|
||
// create plain data object | ||
const plainData = {} | ||
Object.keys(data).forEach(key => { |
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.
Rather than whitelisting props above, it might be better to blacklist property keys which should not be collected.
Fixed the dummy instance's prototype to actual |
That's smart. I wanted to do this in the original version! |
@ktsn any idea on when this will be updated on NPM? |
@michaelkrupp Maybe after #30 is merged? |
I noticed this causes error if it is used with Babel because the dummy object does not inherit component class constructor. |
This PR enable to declare initial data as class properties for components. This let us define Vue component more native class-like style.
Example:
...will be converted into: