News for hackers. Stuff that matters.
Re:New Features in Vue 3 by cies on Tuesday October 29, 2019 @05:07PM (#21392033)
I was hoping for less (or non-at-all) "stringly typing".

Then I saw this: <button @click="increment">

And this

    function increment() {
      count.value++
    }
I have a hard time to deal with that the string "increment" is used to refer to the function increment() in 2019.

There must be a way to use the actual symbol for this instead of a string?

Re:New Features in Vue 3 by ng12 on Tuesday October 29, 2019 @05:36PM (#21392334)
> I was hoping for less (or non-at-all) "stringly typing".

It's the curse of the template. Once you have them you inevitably start encoding more of your logic in magic-voodoo template directives.

Re:New Features in Vue 3 by frenchman99 on Tuesday October 29, 2019 @05:15PM (#21392114)
The devtools (Jetbrains Webstorm for instance) automatically detect that `increment` refers to the method. So it actually works quite well in practice. And you can use @click="increment(any, args, here)" if you want. The syntax @click="increment" is just syntactic sugar for @click="increment($event)", I think.
Re:New Features in Vue 3 by mpolichette on Tuesday October 29, 2019 @05:38PM (#21392362)
It's cool if tooling helps with this. Thats important.

I'm mixed on vue because of the string bindings. I really like to know where my variables are coming from and really hate when two dependent uses but not actually the same thing...

That said, I'm happy to re-evaluate my stance... so what does it mean to be "the same thing"? I suppose in the past, I would say that the compiler thinks the things are the same, and it would be easy to change either:

1. If it is a value, I can set/change it in a single spot

2. If it's a token, it is easy to detect and change everywhere, and tooling will help my avoid misses.

That said, in React, if you were to mess up a 'token', the runtime would be very upset and it would be hard to have something like `onClick={incremant}` (note the a). Tools would make it super easy to spot.

What does vue do if you miss-type your bindings?

Re:New Features in Vue 3 by ktpsns on Wednesday October 30, 2019 @01:59AM (#21395022)
> That said, in React, if you were to mess up a 'token', the runtime would be very upset

The same is of course true for Vue. At runtime, it will spit an error if it doesn't know that token (variable, function, whatever it is).

My feeling is what you don't like are really the quotation marks because it looks weird. I had a similar feeling when I started with vue. However, it is really a matter of taste if you prefer the Vue @click="foo" or onClick={foo} syntax.

Re:New Features in Vue 3 by mpolichette on Wednesday October 30, 2019 @07:58PM (#21404349)
So, when the jsx is compiled for react onClick={foo} is really just part of an object: `{ onClick: foo }` which is actually using the token.

Believe me, I agree to an extend its a matter of taste, but I too like that my underlying understanding of whats happening under the hood can be followed by a raw debugger without following string based mappings.

In react I can set a debugger endpoint right before the return of render and see what all my local variables are... is anything like this possible in vue?

Re:New Features in Vue 3 by teniutza on Wednesday October 30, 2019 @04:24AM (#21395569)
I agree with you on the preference part. I share the same preference as the GP. I've played a bit with Vue in the past, at the same time I was testing React. I've enjoyed Vue but the strings and template were a grim reminder of the Angular not-so-fun-times and passing members around per-reference and not "per string" made more sense in the general JavaScript way of programming, and so I ended up sticking with React.

Even with tooling support, those strings still make me wanting to look away...

Re:New Features in Vue 3 by aliveupstairs on Tuesday October 29, 2019 @06:00PM (#21392559)
throw an error saying "incremt is referenced during render..."

I personally think this is a non-argument to begin with, but the new API coupled with the fact that Vue supports the render function and JSX would give you what you want.

Re:New Features in Vue 3 by lima on Tuesday October 29, 2019 @05:38PM (#21392361)
Still makes it harder to refactor, use code analysis/indexing tools and so on.
Re:New Features in Vue 3 by cooperadymas on Tuesday October 29, 2019 @05:51PM (#21392472)
Since the way you build a vuejs application encourages breaking your code into small, mostly self contained, focused components this is rarely a real problem in my experience.

Tooling also seems to deal with it just fine.

Re:New Features in Vue 3 by cremp on Tuesday October 29, 2019 @05:22PM (#21392192)
I think what he means is why not use ++ in the click handler. We don't need a function to increment something.

Standard HTML, onclick="var++"

Re:New Features in Vue 3 by ry4nolson on Tuesday October 29, 2019 @05:28PM (#21392249)
No, I think he's referring to the fact that the function increment is called by interpreting the string "increment".
Re:New Features in Vue 3 by aliveupstairs on Tuesday October 29, 2019 @06:05PM (#21392594)
you can do exactly that, they just wanted to showcase the methods option. often you would switch true to false doing:

`@click="isSomething = !isSomething"`

Re:New Features in Vue 3 by cooperadymas on Tuesday October 29, 2019 @06:12PM (#21392654)
Exactly this. Template directives support a lot of JS functionality (while not encouraging it, like JSX does). That said, except in rare, extremely simple cases I still prefer wrapping that logic in a computed property or method, as it will inevitably grow more complex later.
Re:New Features in Vue 3 by bradstewart on Tuesday October 29, 2019 @05:12PM (#21392089)
You can use render functions instead of templates if you really want that.

It doesn't bother me though. Tooling (ESLint or TypeScript) will catch typos, missing methods, etc for you.

Re:New Features in Vue 3 by zamalek on Tuesday October 29, 2019 @05:46PM (#21392428)
TSX is supported by Vue and, unlike templates, that is not opaque to the compiler. I recently switched the code in a side project of mine to TSX and it was worth the change.
Re:New Features in Vue 3 by Rapzid on Tuesday October 29, 2019 @06:51PM (#21392956)
Do you have any pointers on setting up TypeScript properly for the jsx render function while preserving intellisense? "Supported" is a bit tenuous based on the manual setup and shim creation required to get it all working nicely..
Re:New Features in Vue 3 by zamalek on Tuesday October 29, 2019 @07:13PM (#21393086)
This is my setup:

- vue, @vue/composition-api

- Rollup

- Babel: @babel/preset-typescript, @babel/preset-env, @vue/babel-preset-app, babel-preset-vca-jsx

- Just pass `extensions: ['.js', '.jsx', '.ts', '.tsx']` to the Rollup babel plugin.

Make sure you are using createComponent inside a TSX file, and you'll get every feature that TS has to offer (as it is all native TS). Intellisense and static types are the only reason I dropped SFCs.

I'm not sure how this would work with Webpack, I've been enjoying Rollup more as things have just worked with no thought involved so far. I'm sure it can be done, though.

Re:New Features in Vue 3 by aitchnyu on Thursday October 31, 2019 @07:08AM (#21407483)
What's your Vue+Rollup configuration?
Re:New Features in Vue 3 by Vinnl on Wednesday October 30, 2019 @03:40AM (#21395365)
But that feels a bit like saying you can use React without JSX. Sure, you can, but it appears that the templates are a major selling point for Vue to many people. That's the part that's most baffling. (Well, not really baffling, as it's a pretty subjective matter. But not for me, at least :)
Re:New Features in Vue 3 by hateful on Tuesday October 29, 2019 @06:02PM (#21392576)
In vue you can do <button @click="increment()"> and it treats it the same. I tend to put the (), especially since I am almost always passing in some sort of object inside a loop.
Re:New Features in Vue 3 by hermanradtke on Wednesday October 30, 2019 @10:41PM (#21405241)
Isn’t that still a string?
Re:New Features in Vue 3 by jsmith45 on Tuesday October 29, 2019 @05:28PM (#21392251)
Would you be happier with the following?

<button @click=increment>

That is legal (or at least it is supposed to be, I've not tested it), but is not really different. This part of Vue parsing is dictated by the whatwg html specification, and the html spec says that <html lang=en> and <html lang="en"> are the same thing.