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

warns when duplicated props from mixins #1431

Closed
TerenceZ opened this issue Oct 16, 2015 · 6 comments
Closed

warns when duplicated props from mixins #1431

TerenceZ opened this issue Oct 16, 2015 · 6 comments
Labels

Comments

@TerenceZ
Copy link

Sometimes we would abstract some behaviours into mixins, for example: A, B and C. If A is mixed in B and C, and if the A has a required prop named a, then when component D requires B and C in mixins, vue will warn the a is required even if a value passed to a. Because one of the prop check from B or C digests the value of a, leaving another one nothing.

By the way, are there any suggestions to use / compose mixins? Because of the features of mixins, sometimes some implicit conflicts will raise up and not easy to find out. And in addition, the mixins require the component to obey some implicit interfaces, which lead to hard to maintain the codes.

@yyx990803
Copy link
Member

Looks like this is because props are not properly de-duped when merged. However it seems a bad idea to have duplicate props in multiple mixins. I don't think this is the mixin mechanism's problem, but rather how you use mixins...

IMO when you use multiple mixins, they should each serve a distinct purpose. If you have two mixins that have overlapping responsibilities then you probably need to rethink the design.

@TerenceZ
Copy link
Author

Thanks, having duplicated props is actually a bad idea, I think I should remove the dep on A for B and C, then require the mixins [A,B,C] in component D:)

@OEvgeny
Copy link

OEvgeny commented Oct 19, 2015

Just curious. Imagine I have a mixin with some prop, I need to redefine its prop default value in component. How can I do it?

@azamat-sharapov
Copy link

@OEvgeny it will probably work like described in docs, not sure about props thought: http://rc.vuejs.org/guide/mixins.html#Option_Merging

@yyx990803
Copy link
Member

@OEvgeny that sounds like a bad idea to me. Ideally you don't want the sub fields of an option to be merged from multiple sources, especially when it is an object like a prop. It makes your code very hard to reason about. Hooks on the other hand makes more sense.

@OEvgeny
Copy link

OEvgeny commented Oct 19, 2015

@yyx990803 @azamat-sharapov thank you. I also think there is something wrong with my approach... :)

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

No branches or pull requests

4 participants