-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Warn against duplicate props/data fields #1166
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
Comments
👍 |
Calling it |
How will this work with 2 way binding? At present I send a prop (which can be blank) and my data defines defaults and this works nicely. By separating them I would need to merge defaults with the prop data? Or create the correct data structure before creating the component (But I'm trying to make the component responsible for the data not the app). Make sense? |
@Mat-Moo not sure if I get what you mean. You can declare defaults for props directly: props: {
a: {
type: Number,
default: 123
}
} |
Hmm I'm using v-repeat on an array to create components so data comes in anyway so maybe irrelevant. |
In functions, vars passed via parameters and local variables are in the On Sun, Aug 16, 2015 at 10:04 PM, Evan You [email protected] wrote:
|
Would this add more syntax to things like One of Vue's biggest features is its simplicity. I don't see how this proposal has enough benefit to excuse the added complexity. Things like removing "perfection is attained not when there is nothing more to add, but when there is nothing more to remove." - Antoine de Saint Exupéry |
@mark-hahn Yes, this would make your template a bit more verbose. It's a tradeoff between conciseness (note - not necessarily simplicity) and explicitness. A component is stateful and its state can change over time - this is different from, say, a pure function call. It could be helpful to clearly know which part of the state is external and thus can change without the component itself doing anything. That said, I'm also not 100% sure on this proposal yet. Would love to get more feedback from others. |
Objects passed into functions can also change without a function's help. You can't tell an object from a string using the syntax. Adding syntax for that, like hungarian notation, would be horrible. Adding scope meaning to variables using syntax is a slippery slope. Should vars passed in to a function look different than local vars which look different than closure vars which look different than global vars? |
I'm still not sure on this... When using 2 way bindings would it be data or a prop? |
In my opinion Vue is one of the best frameworks I've ever seen because of its simplicity. Moving the params in its own scope, would make it's structure more complex. Why not show a warning if there is a param and a data property with the same name? |
@gamperl yeah, that could work too. Maybe something like "Don't redefine a prop in data. Use prop default value instead." |
I would actually like to have |
+1 for warning instead of different namespaces. |
Warning sounds like a good idea. |
Why not to embrace the probable interference taking in the next way: |
It was called |
+1 for just emitting a warning on name clashes. The case of having a param and data attribute with the same name seems like it will lead to trouble and confusion. |
@azamat-sharapov why not to call it just |
@karevn no point in introducing breaking changes just out of naming preferences. |
Implemented in 1.0.0-alpha branch. |
Problem
Currently the props are merged with the instance's own
data
, which has a few problems:data
functions, but the same field returned in data gets overwritten by the prop.Proposal
Move props into its own name space, for examplethis.props
. This avoids the merging problem (we can either makeprops
a reserved field or make it$props
) and makes it explicit that something is a prop that is obtained from outside the component.Throw a warning if the user defines duplicate fields in
data
andprops
.The text was updated successfully, but these errors were encountered: