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 factory mixins #10868

GerardRodes opened this issue Nov 26, 2019 · 1 comment


Copy link

@GerardRodes GerardRodes commented Nov 26, 2019

What problem does this feature solve?

I would like to somehow be able to define a global factory mixin.

Right now the only way of using a factory mixin is within the component definition, but I think that would be could to define the factory mixin as a global mixin which gets its configuration from a custom $option of the component

What does the proposed API look like?

// main.js
function MyFactoryMixin () {}

  beforeBeforeCreate () { // somehow it should happen before instantiating 
    if (!this.$options.custom) return

    // pushin to current mixins, just a proposal
    this.$options.mixins = this.$options.mixins || []
// MyComponent.vue
export default {
  custom: {
    // config here

This comment has been minimized.

Copy link

@posva posva commented Nov 26, 2019

You can already achieve that by using the custom option inside of the global mixin and making your mixin behave based on that. Other vue libs like vuefire already do that.

Note you can also do:

// MyComponent.vue
export default {
  mixins: [MyFactoryMixin({
    // config here

Which is explicit and allows for types to be inferred

@posva posva closed this Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.