Skip to content

Should MountingOptions that apply properties to createApp vm be prefixed? #18

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
dobromir-hristov opened this issue Mar 26, 2020 · 5 comments

Comments

@dobromir-hristov
Copy link
Contributor

There are a few properties currently that modify the vm returned from createApp, but could be confusing, as the mounted vue component may have the same properties.

Currently these are:

  • mixins - applies the provided mixins globally, but I expected it to just overwrite a mixin on a per component level?
  • plugins - this is self explanatory. Before we would ask them to createLocalVue themselves.
  • provide - provides to all children of the vm. The Mounted component is a top level child so its probably functionally the same?
  • data (uses vm.mixin) - data is merged in a global mixin, wont this overwrite the state in all components?
@lmiller1990
Copy link
Member

lmiller1990 commented Mar 26, 2020

  • mixins: I went with the global one for now just to get something working. Is there a use case where you want to override a mixin on the per component level? I was thinking this more for the use case people want to test a component that would have a global mixin.

  • plugins: by passing them and writing them to the returns app, isn't this more or less the same as a localVue with a plugin?

  • provides: seems fine (not sure if you are asking a question or not)

  • data: yep, idea of the data mounting option to override the data - the current approach overrides all components, which could be a problem. This was the only thing I could find that worked. We should be able to pass an extra argument to that mixin that is the name of the component (or some other unique identifier, via a symbol or something) and do something like

if (getCurrentInstance() === SomeIdentifier) {
  // mixin the data to override component local stte
}

So far everything is more of a "get something working and go from there" than an ideal solution, but thanks for picking up on some of the potential problems. Any ideas to work around these?

@dobromir-hristov
Copy link
Contributor Author

mixins
Current VTU mount api mixes passed properties with those on a component. That way you could mix in your own mixin into a Vue component. I guess you could use something like jest.mock to the same extend.

plugins
It is the same as localVue, correct. But I think globally applied ones, should be separated from the Vue component properties, like data and props.

provides
Was thinking out loud. Should be fine yeah.

data
What if we use that data mixin only on the mounted component?

@lmiller1990
Copy link
Member

lmiller1990 commented Mar 28, 2020

An alternative to localVue (not sure if such a concept will exist in Vue 3) could be something like:

const wrapper = mount(Foo, {
  globals: {
    plugins: [...], 
    mixins: [...]
  }
})

@dobromir-hristov
Copy link
Contributor Author

Yeah, not a bad idea, I like it :)
We cant allow them to pass their own App Instance though, as it no longer makes sense.

@dobromir-hristov
Copy link
Contributor Author

Closed in #31

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

No branches or pull requests

2 participants