Skip to content
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

feat(runtime-core): add special property to get class component options #821

Merged
merged 2 commits into from
Mar 12, 2020

Conversation

ktsn
Copy link
Member

@ktsn ktsn commented Mar 11, 2020

This PR adds a special property __vueClassComponentOptions to process class style component.

If a component passed to createVNode is a function and having __vueClassComponentOptions property, it gets the actual component options from that property. To decouple with vue-class-component as possible, Vue core only knows where the options object of class component is stored. vue-class-component should convert the class to a component options object.

Vue v3 + vue-class-component is already working with this change. The brief idea of the implementation looks like below:

// Providing Vue base constructor from vue-class-component
export class Vue<Props = unknown> implements ComponentPublicInstance<{}, {}, {}, {}, {}, Props> {
  // Define a getter to convert the class to options object
  static get __vueClassComponentOptions() {
    // converting logic here...
  }
}

// ------

// Usage
class App extends Vue<{ name: string }> {
  greeting = 'Hello, ' + this.$props.name
}

@@ -214,6 +215,11 @@ export function createVNode(
type = Comment
}

// class component normalization.
if (isFunction(type) && '__vueClassComponentOptions' in type) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a shorter key to save a few bytes? Maybe __vccOpts? (I assume this key will be fully internal and never exposed to the user)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, renamed.

@yyx990803 yyx990803 merged commit dd17fa1 into vuejs:master Mar 12, 2020
@ktsn ktsn deleted the class-component branch March 13, 2020 02:57
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.

2 participants