Giter Club home page Giter Club logo

Comments (17)

leopiccionia avatar leopiccionia commented on August 16, 2024 14

The API change presented in this PR and Robson @phiter's tweet has been suggested many times in Vue's main repo.

One of those times, @yyx990803 argued that :prop (= :prop="prop") looks too similar to prop (= :prop="true"). I don't know if he changed his mind.

At first sight, I feel like this change trades faster writing with slower comprehension (not a good deal), as it departs from HTML's familiar key=value flow. I might get used to it, though.


P.S. Are you aware about the <my-component v-bind="{ name, whatever }" /> shorthand?

from rfcs.

GavinRay97 avatar GavinRay97 commented on August 16, 2024 5

Wow, holy smokes. Was not expecting that, half a decade later! 😁

from rfcs.

phiter avatar phiter commented on August 16, 2024 4

As I mentioned, I think this is a really nice improvement if added. I find myself writing :expanded="expanded" a lot when writing code.
I don't see any drawbacks of using this. The only thing I could think of is if you simply want to pass an empty prop as you can do with most Vuetify components, for example:

<v-btn outlined>

But that would of course not use the value defined in data since it doesn't have v-bind.

Also I understand it could make the code a bit weird to read for people unaware of the feature, but so does other Vue features like CSS v-deep or >>>.

v-bind="{ name, whatever }" is also great but it's still a bit more verbose.

Take this Vuetify playground as an example, most of the data properties are repeated.

<v-text-field
    v-model="model"
    :label="label"
    :hint="hint"
    :placeholder="placeholder"
    :shaped="shaped"
    :outlined="outlined"
    :rounded="rounded"
    :solo="solo"
    :single-line="singleLine"
    :filled="filled"
    :clearable="clearable"
    :persistent-hint="persistentHint"
    :loading="loading"
    :flat="flat"
    :counter="counterEn ? counter : false"
    :dense="dense"
/>

Could be way shorter with the proposed change.

Also it looks more like ES6 objects which accepts a similar syntax as @GavinRay97 mentioned.


Also, @leopiccionia how do people still remember this Robson stuff? lmao it happened five years ago.

from rfcs.

michaeldrotar avatar michaeldrotar commented on August 16, 2024 4

Seems reasonable.. to toss another slight deviation into the ring, I prefer something like this currently.. reads well, highlights well, digests easily imo

<v-text-field
  v-model="model"
  v-bind="{
    label, 
    hint, 
    placeholder, 
    shaped, 
    outlined, 
    rounded, 
    solo, 
    filled, 
    clearable, 
    loading, 
    flat, 
    dense
  }"
  :single-line="singleLine"
  :persistent-hint="persistentHint"
  :counter="counterEn ? counter : false"
>
</v-text-field>

There's another RFC floating around about adding property negation (!prop) so I could see a world where :prop prop !prop might not be ideal.

from rfcs.

GavinRay97 avatar GavinRay97 commented on August 16, 2024

At first sight, I feel like this change trades faster writing with slower comprehension (not a good deal), as it departs from HTML's familiar key=value flow. I might get used to it, though.

I would make the argument that when dealing with component attributes with a colon :, my frame of mind shifts from HTML to Javascript. When I see a bound property, I immediately see the expression as a Javascript, not HTML. If you want to make the argument that attributes should follow the key=value flow, then any expressions and inline statements to bound attributes should be explicitly disallowed.

I think we can come to a consensus that Vue templates are not HTML, nor are they JS. They are an independent entity with slightly different semantics. And that's okay. Those unique semantics are why we love Vue.

This sort of binding mirrors the way I would expect JS object expressions to behave. The syntax is identical to ES6 property value shorthands, which, in my experience, nearly everyone uses. In the context of "Bound Vue attribute = JS expression", I think there is little ambiguity as to mechanics or intent here.

P.S. Are you aware about the <my-component v-bind="{ name, whatever }" /> shorthand?

I did find that during researching whether this proposal/RFC has been presented before. I understand that functionally, the result is the same, but the appeal and attraction of Vue to most I believe has always been about it's ergonomics and semantics. We write Vue because it is beautiful and comprehensible, and to me, the object values v-bind are not particularly either of those.

from rfcs.

amoliski avatar amoliski commented on August 16, 2024

@phiter That playground could use this to tighten up the syntax, but I think in that case the verbosity is on purpose.

<v-text-field  
   v-model="model"  
   v-bind="{label, hint, placeholder, shaped,
      outlined, rounded, solo, filled,
      clearable, loading, flat, dense,
      'single-line':singleLine,
      'persistent-hint':persistentHint,
      counter: counterEn ? counter : false,
      }">
</v-text-field>  

https://codepen.io/amoliski/pen/pooJgvY

from rfcs.

phiter avatar phiter commented on August 16, 2024

@amoliski this syntax is worse. Vue style guide recommends using one prop per line if you're going to pass three or more props. I think this is a bit harder to read than what we're used to.

Of course, we could use this instead:

<v-text-field
    v-model="model"
    v-bind="{
        label,
        hint,
        placeholder,
        shaped,
        outlined,
        rounded,
        solo,
        filled,
        clearable,
        loading,
        flat,
        dense,
        'single-line':singleLine,
        'persistent-hint': persistentHint,
        counter: counterEn ? counter : false,
    }"
/>

This would make more sense, but now you have commas and can be weird at first sight.

from rfcs.

amoliski avatar amoliski commented on August 16, 2024

Fair enough, I went a bit overboard collapsing it down to take up less space in the comment.
The syntax isn't great, but it sure beats typing out fifteen equals signs and thirty quotes.

from rfcs.

CyberAP avatar CyberAP commented on August 16, 2024

What would :[prop] mean then? Dynamically assigned prop with dynamically assigned value?

from rfcs.

phiter avatar phiter commented on August 16, 2024

@CyberAP that should either be invalid or resolve to the data referenced by prop.

from rfcs.

csmikle avatar csmikle commented on August 16, 2024

@amoliski this syntax is worse. Vue style guide recommends using one prop per line if you're going to pass three or more props. I think this is a bit harder to read than what we're used to.

Of course, we could use this instead:

<v-text-field
    v-model="model"
    v-bind="{
        label,
        hint,
        placeholder,
        shaped,
        outlined,
        rounded,
        solo,
        filled,
        clearable,
        loading,
        flat,
        dense,
        'single-line':singleLine,
        'persistent-hint': persistentHint,
        counter: counterEn ? counter : false,
    }"
/>

This would make more sense, but now you have commas and can be weird at first sight.

This looks good to me, nothing wrong with some commas. It's not an extra character since the colons are saved

from rfcs.

hecktarzuli avatar hecktarzuli commented on August 16, 2024

I'd love to see this shorthand become a reality. So many of our properties are :src="src", width="width" etc..

from rfcs.

prashantpalikhe avatar prashantpalikhe commented on August 16, 2024

Would love to have this terse syntax

from rfcs.

ojvribeiro avatar ojvribeiro commented on August 16, 2024

This would be appreciated.

from rfcs.

tikudev avatar tikudev commented on August 16, 2024

I would also love this. It is a little funny when you dig into this topic and find that this idea comes up multiple times each year and everyone seems to have the same syntax-intuition. That to me sounds like this syntax can be intuitively understood, since a similar syntax is used by js property shorthand. I get a question about a shorthand for props nearly every time I teach vue to a new developer.

@yyx990803 stated his opinion on the topic in the year 2016. Given the many many request I hope he reconsiders.

Vue is losing some of its popularity lately and I think that such a little Quality of Life Improvement could go a long way.

from rfcs.

tikudev avatar tikudev commented on August 16, 2024

Since there was no RFC-Discussion open; I created an RFC regarding this issue. I proposed a solution which effectively supports this syntax:

<v-text-field
    v-model="model"
    {label}
    {hint}
    {placeholder}
    {shaped} />

from rfcs.

phiter avatar phiter commented on August 16, 2024

This has been added to Vue 3.4 via this PR vuejs/core#9451
There was another issue posted here too with this same proposal: #405

from rfcs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.