-
Notifications
You must be signed in to change notification settings - Fork 545
docs(boolean-prop-shorthand): rfc for the feature #81
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
Conversation
I like this idea at first glance. |
This RFC should address the grammar ambiguity, though. |
🤔But my proposed use case is an anti-pattern actually (https://eslint.vuejs.org/rules/no-boolean-default.html). |
Nothing new in this RFC. |
In the same way we deal with duplicate attributes now? <div :data-value="1" :data-value="2"></div> which I believe is a compiler error.
Well, that rule is "Uncategorized" (not even enabled by the |
At face value, it seems like a pretty cool idea. However, I'm wondering about its usefulness. I'm wondering, because, the idea of boolean props should be this. If the boolean flag should be set, it means you want whatever that flag setting does to happen, so you just write the prop out, as demonstrated in this RFC. However, if you don't want whatever the boolean flag does to happen, as in it would be false, you simply don't add the prop, which is infinitely easier than this proposal. Hmmmm...... 🤔 Scott |
Unless the default prop value is |
Which is an anti-pattern, if I'm not mistaken.... edit: Maybe some more poignant code examples would highlight the problem trying to be solved? Scott |
Not really. Just like any other kind of values that we may want to have default values. Example -
When components, specially dynamic components are built that are generated from a configuration, you want pretty much all of your props to have default values and then look at configuration for overrides.
This forces you to only come up with props that are negative in nature and kind of says that everything is true by default unless you specificy. Works great for props like
not for
Take an example. If I don't add the
Again, this RFC isn't something we can't live with. It is just a syntactic sugar so I can totally see if this doesn't seem worthwhile. However, I genuinely believe it will bring better UX to developers who need to use boolean props. |
When reading the examples <!-- OLD -->
<my-component :standalone="false"></my-component>
<!-- NEW -->
<my-component !standalone></my-component> I actually didn't notice the I do agree it's easy to mix setting boolean For instance, a button could have different appearances like raised, text, or flat -- I've seen components handle this with I agree that I'd like to see more examples of where this would be helpful for dealing with hard-coded booleans. Maybe there's a better solution. To the earlier concerns of default values, I also usually want to phrase my properties such that For instance, if I'm showing a loading indicator component that has some css transitions when it moves in and out of its loading state.. the default state should probably be that it I also get tripped up with |
If you have to put logic behind the boolean to toggle or switch it, then you have to write it out anyway. This RFC won't help in those situations. I will stick to what I said. Default true booleans are an anti-pattern. Scott |
@michaeldrotar about missing the
|
To clarify, it's not that I didn't see anything, it's that for a good minute I thought it was a colon. They look very similar. Just an initial impression. |
I dislike this proposal. </opinion> |
@sustained, @zhangenming - I would love to know why. Why do you think it should not be done? |
Oh, I read the proposal again and then I rechecked the docs and I figured out the issue here. I had no idea you could do Now this proposal makes complete sense and in that case I am okay with it. That is why I was against it - it seemed like a strange new syntax that only works for one of two possible cases ( My apologies. |
Well, because Vue will imply a true value by just adding the prop name, it is an anti-pattern to do anything else for false. Or rather, false = not adding the prop at all, which is much easier to understand, quicker to do and it's less verbose than this suggestion. Default true boolean props are an anti-pattern in Vue (at least they should be IMHO). Scott |
After reviewing the comments so far and a round of voting among core team members, we believe this is not something we will be implementing because the benefits doesn't justify adding a new syntax (which is an extra thing to remember for all users). Thanks for submitting your idea though! Regarding the web component wrapper issue mentioned by @sodatea - I think it should be fixed in the web component wrapper instead. |
@yyx990803 - Thanks for the comments. I kind of always knew it wouldn't get implemented but happy to have tossed the idea around and get so many different perspectives. |
Rendered