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(reactive): allow usage of reactive before Vue.use #515

Merged

Conversation

pikax
Copy link
Member

@pikax pikax commented Sep 14, 2020

Allowing define reactive and ref before the Vue.use, the only caveat is when you have different vue versions installed.

I think this is a pretty edge case and most of the time the user will use the version from required('vue')

Note: would be nice to validate if reactive was used and if it was before the Vue.use and the Vue.use resolves to a different Vue constructor we could warn it

// something like this
export function setVueConstructor(Vue: VueConstructor) {
  if (__DEV__ && vueConstructor) {
    warn('Another instance of vue installed')
  }

  if(__DEV__ && !vueConstructor && hasReactiveBeenUsed && vueConstructor !== vueDependency) {
    warn('reactive was used globally with a different Vue instance, this might cause reactivity to fail')
  }
  vueConstructor = Vue
  Object.defineProperty(Vue, PluginInstalledFlag, {
    configurable: true,
    writable: true,
    value: true,
  })
}

@pikax pikax requested a review from antfu September 14, 2020 20:49
Copy link
Member

@antfu antfu left a comment

Choose a reason for hiding this comment

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

This is definitely good to have. Not sure if there are any caveats for bundles though, guess we can just revert it if something really goes wrong. LGTM 👍

@pikax pikax merged commit 89fd11c into vuejs:master Sep 15, 2020
@pikax pikax deleted the feat/allow_usage_ref_and_reactive_without_use branch September 15, 2020 14:21
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