Skip to content

BV does not follow Vue global name/function plugin convention #3849

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

Closed
Andrei-Pozolotin opened this issue Aug 10, 2019 · 4 comments · Fixed by #3850
Closed

BV does not follow Vue global name/function plugin convention #3849

Andrei-Pozolotin opened this issue Aug 10, 2019 · 4 comments · Fixed by #3850

Comments

@Andrei-Pozolotin
Copy link

BV exposes itself:

  1. as window.bootstrapVue, not as window.BootstrapVue

compare global.VueRouter = factory()
https://github.com/vuejs/vue-router/blob/dev/dist/vue-router.js#L9

vs global.bootstrapVue = factory()
https://unpkg.com/browse/bootstrap-vue@2.0.0-rc.27/dist/bootstrap-vue.js

  1. another inconsistency: function vs object
VueRouter
ƒ VueRouter (options) {
  if ( options === void 0 ) options = {};
  this.app = null;
  this.apps = [];
  this.options = options;
  this.beforeHooks = [];
  this.resolveHooks = [];
  this.afterHooks = …
bootstrapVue
{install: ƒ, setConfig: ƒ}
  1. that brings in needless confusion :-)
@tmorehouse
Copy link
Member

tmorehouse commented Aug 10, 2019

The global name being window.bootstrapVue is a legacy name (been htat way since before I started with the project), although we may consider adding in a PascalCase version (create both for backwards compatability). Although installing as a property on global isn't really required, as BootstrapVue (when used in browser script tags) will auto install itself via the Vue global.

Vue supports both object and function for plugins, and Vue's doc's actually provide examples in the object format: https://vuejs.org/v2/guide/plugins.html#Writing-a-Plugin

Object and Function as plugins are acceptable to Vue. so I don't see a need to change from passing Function vs Object as the plugin (an the former actually has benefits when creating the CommonJs bundle version)

@Andrei-Pozolotin
Copy link
Author

#3850 looks good, thank you

@tmorehouse
Copy link
Member

tmorehouse commented Aug 11, 2019

@Andrei-Pozolotin Note that VueRouter is also a constructor function (technically it is a class creator), for creating a router instance to pass to an app. While it is a function, Vue, when one does Vue.use(VueRouter), sees it an an Object with an install property (functions and classes in JavaScript are actually based on the Object prototype).

Vue first inspects the passed plugin as an Object and looks for an install property, and if found executes it, otherwise if it sees the plugin as a Function without an install property it assumes the function is the installer (which it is not in the case of VueRouter)

The BootstrapVue plugin is not a constructor (one doesn't use foo = new BootstrapVue()), hence it is a plugin Object with an install property.

So to your point number 3, it is not leading to endless confusion (if one understands Vue's internals).

@Andrei-Pozolotin
Copy link
Author

ok, clear, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants