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

Global API updates: more details on mounting behavior + replacement for Vue.prototype #117

Merged
merged 2 commits into from
Mar 25, 2020

Conversation

yyx990803
Copy link
Member

@yyx990803 yyx990803 commented Jan 21, 2020

  • More details on the mounting behavior change
  • Offer a replacement for attaching properties to Vue.prototype in 2.x

Rendered

@yyx990803 yyx990803 added core 3.x This RFC only targets 3.0 and above amendment Updates to an active RFC labels Jan 21, 2020

// After
const app = createApp()
app.config.globalProperties.$http = () => {}
Copy link
Member

Choose a reason for hiding this comment

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

how would we access this inside the setup function?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is essentially a legacy escape hatch and not for setup function. You should just import things directly or use provide/inject in setup functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work for legacy apps that use multiple instances and apply Vue.use globally since you'd have to run app.use in every one of them. If that's required only for legacy plugins shouldn't that be included only in the compatibility build with global registration on the prototype as usual? That way you won't have to rewrite that much and stay with global Vue.use. Why would you need that hack for anything but legacy plugins? (Assuming that the new strategy for plugins is to utilize provide\inject).

Copy link
Member Author

Choose a reason for hiding this comment

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

The "legacy" term I used was incorrect - it should be for "options/this-based usage". Even with setup function this can still be used to expose globally available properties to templates.

With the global API change there is no once-for-all global configs anymore. 2.x multi-root-instance apps will have to be updated to configure each root instance individually. If all root instances share the same config, then it can be extracted into a shared function.

@@ -44,6 +46,8 @@ app.mixin(/* ... */)
app.component(/* ... */)
app.directive(/* ... */)

app.config.globalProperties.customProperty = () => {}
Copy link
Member

Choose a reason for hiding this comment

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

Is there an interface that can be extended to type new properties?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd say just don't use this if using TS.

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this be better for people migrating TS projects using libraries that are not adapted yet (or that may never completely adapt) to the inject/provide?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no way to make this work in TS though. If users insist on using this with TS they'd have to shim the types themselves.

Copy link
Member

Choose a reason for hiding this comment

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

If users insist on using this with TS they'd have to shim the types themselves

Oh yeah, I just thinking of exposing an interface that can be extended by users to add their own typings

yyx990803 added a commit to vuejs/core that referenced this pull request Mar 25, 2020
@yyx990803 yyx990803 merged commit 7eb78c2 into master Mar 25, 2020
rzning added a commit to rzning/daily-notes that referenced this pull request Apr 1, 2020
mode details on mounting behavior
replacement for Vue.prototype

vuejs/rfcs#117
@yyx990803 yyx990803 added the feat: global api Changes related to global API label Jul 1, 2020
@bencodezen bencodezen mentioned this pull request Jul 6, 2020
25 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x This RFC only targets 3.0 and above amendment Updates to an active RFC core feat: global api Changes related to global API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants