News for hackers. Stuff that matters.
Re:Why I left React for Vue by ystrdytmrrw on Tuesday December 25, 2018 @09:49PM (#18760152)
I just can't get behind ` <div v-if="unreadMessages.length > 0">` after years of React. At least with React it is pure JS/TS - No magic.

However I must admit, the css story within vue is more interesting than React and its collection of CSS-IN-JS libraries.

Re:Why I left React for Vue by fro0116 on Tuesday December 25, 2018 @10:23PM (#18760270)
Going to have to disagree with the comment on CSS-in-JS.

CSS-in-JS is one of my favorite parts of the React ecosystem. Style as a function of state is such a natural extension to React's programming model that I end up cringing a bit every time I have to go back to writing a bunch of different classes and applying them conditionally. Representing styles as data also means you have the full power of JavaScript at your disposal to compose and manipulate styles (not to mention access to a proper module system), whereas with plain CSS you're limited to a handful of mixins offered by whatever post-processor you choose, and those in turn are generally limited in terms of expressiveness themselves by nature of only being able to perform simple string interpolations, since that's the format they have to deal with.

I think these benefits are analogous to the benefits of HTML-in-JS a la JSX over traditional JS-in-HTML templates. I'm honestly struggling to see why someone would prefer HTML-in-JS but not CSS-in-JS.

Re:Why I left React for Vue by unclebucknasty on Tuesday December 25, 2018 @11:40PM (#18760563)
It's funny to hear people debate CSS in JS vs. templates, etc. For me, the answer is none of the above.

That is, all of these frameworks are underpinned by a certain awfulness that is born of the impedance mismatch between applications vs Web. The right framework would abstract away CSS, templating, HTML, and all of the other awful that we've unfortunately come to accept as the cost of doing business when building Webapps.

So far as I know, that framework doesn't exist yet.

Re:Why I left React for Vue by fro0116 on Wednesday December 26, 2018 @07:03AM (#18761765)
Curious if you could point to some solution for building apps outside of the web ecosystem that doesn't have this impedance mismatch you're talking about?

Pretty much all of the UI frameworks on any platform that I personally know of use some combination of an XML-based templating system for laying out components and a programming language to implement the logic behind those components, which is fairly analogous to how the web has HTML for templating and JS for implementing logic. Perhaps the impedance mismatch you're talking about lies in how the web handles styling, i.e. CSS itself and how it's not integrated into either the templating or the logic side like certain other frameworks but is rather a separate independent piece altogether?

Just trying to understand where you're coming from, because in my view React itself _is_ already a powerful abstraction over the DOM (in React you write components, and rendering those components to the DOM is an implementation detail involving an entirely separate library, react-dom, which can be seamlessly swapped with libraries dealing with the implementation detail of rendering to other targets like react-native, react-canvas, react-sketchapp, etc), and CSS-in-JS in the React ecosystem is itself a powerful abstraction over CSS for implementing styling as a function of state (though this abstraction hasn't yet been taken advantage of quite as much, the only notable exception I know of being glamorous-native, which implements glamorous's style as a function of state pattern on top of react-native's Stylesheet primitive rather than on top of CSS).

Re:Why I left React for Vue by unclebucknasty on Wednesday December 26, 2018 @11:51PM (#18767401)
>point to some solution for building apps outside of the web ecosystem that doesn't have this impedance mismatch you're talking about

>all of the UI frameworks on any platform that I personally know of use some combination of an XML-based templating system

I also know of no other approaches with significant traction. That's the problem I'm referencing: they all take the approach of starting with technology that was designed for serving static documents then, essentially, layering on some cruft that attempts to adapt it for dynamic environments. This is obviously because the delivery platform (browsers) still rely on the underlying tech. But, there's no reason this can't be completely abstracted away by our tooling/frameworks.

I understand your references to React's abstraction but, in the end, it still comes down to CSS-in-JS, HTML-ish templating, etc. So, React's is not really an abstraction "where it counts". Think about it: why are we writing CSS at all when what we want is an application? In other words, if there were no Web and you wanted to build out a platform and/or development ecosystem for constructing applications from scratch, would CSS or XML-based templates, etc. be a design-choice you'd make? Of course not. They are wonky and inefficient for these purposes. Meanwhile, we're at the point where pre-compiling on these frameworks. So, why isn't there a framework that looks more like what we'd build from scratch that then compiles down to the Web-ish stuff we're working in (i.e. JSX or similar); thus completely abstracting away everything Web?

Because if you step back and look at, say, JSX through this lens, it's slightly insane. Not picking on React here--just following up on your example. This problem is endemic to virtually all frameworks that have gained significant traction.

There's a better way and it's frankly probably more akin to Swing or Visual Basic than it is to anything we've seen thus far.

Re:Why I left React for Vue by geonik on Wednesday December 26, 2018 @07:27AM (#18761826)
There is! It is called Qooxdoo, exists for years, and works wonders around the impedance mismatch.
Re:Why I left React for Vue by molszanski on Tuesday December 25, 2018 @10:34PM (#18760308)
What do you mean by css story with vue? You mean css modules? Or having one file for css, html, and js?
Re:Why I left React for Vue by mattigames on Tuesday December 25, 2018 @10:17PM (#18760251)
That's also how angular does it, i don't see anything magical to be honest, just syntax sugar over

    if (unreadMessages.length > 0) {  addComponent(this) }
Re:Why I left React for Vue by ng12 on Tuesday December 25, 2018 @10:20PM (#18760264)
But it's a lot of syntactic sugar. There's a second, stringly-typed language embedded in your HTML template.
Re:Why I left React for Vue by mattigames on Tuesday December 25, 2018 @10:28PM (#18760286)
The only reason for it to be "stringly-typed" is that your IDE doesn't support it.
Re:Why I left React for Vue by nv-vn on Tuesday December 25, 2018 @10:40PM (#18760343)
At the end of the day, it's much more of a hack. The IDE having to guess at what the string does is ridiculous to me, and it's just a ton of extra work for the person who wrote the IDE for no real reason. And now if you want to embed a string inside you need to switch quotes. Plus formatting gets super weird if you have a multiline condition. It's also super confusing for new users. There are so many issues I see with that design that I can't begin to understand why someone would argue in favor of it.
Re:Why I left React for Vue by lucidone on Tuesday December 25, 2018 @10:46PM (#18760363)
A lot of people are familiar with it (and that style) via AngularJS. It may not be as pure, but it's what they know.
Re:Why I left React for Vue by mattigames on Wednesday December 26, 2018 @12:42AM (#18760799)
An IDE doesn't have to guess anything, if the string is preceded by v-if then is code, that's it. Pretty much how a string literal inside eval() could be parsed as code.
Re:Why I left React for Vue by nv-vn on Monday December 31, 2018 @05:09PM (#18797358)
What if another library uses v-if? Or there's no library loaded at all? What if I just wrote a new library that uses c-if? I imagine most IDEs approach this by looking at the string and trying to guess whether it's HTML code or not.
Re:Why I left React for Vue by ng12 on Tuesday December 25, 2018 @10:31PM (#18760297)
It's still stringly typed even if someone wrote an IDE plugin that tries very hard to make it safe.
Re:Why I left React for Vue by orf on Tuesday December 25, 2018 @10:36PM (#18760320)
So just like JSX then?
Re:Why I left React for Vue by ng12 on Tuesday December 25, 2018 @10:44PM (#18760355)
No, because JSX is a 1-to-1 mapping to React.createElement, it's actually just syntactic sugar. There's no variable binding or evaluation.
Re:Why I left React for Vue by liveoneggs on Tuesday December 25, 2018 @10:49PM (#18760374)
finally a clear code snippet
Re:Why I left React for Vue by Tallain on Tuesday December 25, 2018 @10:47PM (#18760366)
You can also do `<div :if="foo">` where `foo` is a computed property (or function with ()) -- nothing specifies you have to write code inside the string, though it seems this is a pretty commonly overlooked ability.
Re:Why I left React for Vue by cageface on Tuesday December 25, 2018 @10:41PM (#18760346)
I've found styled-components to solve just about all my gripes about CSS in React. You even get auto formatting with Prettier.

https://www.styled-components.com

Re:Why I left React for Vue by molszanski on Tuesday December 25, 2018 @10:55PM (#18760398)
What are your gripes?
Re:Why I left React for Vue by cageface on Tuesday December 25, 2018 @11:10PM (#18760449)
I’ve found doing CSS in JS to be a bit awkward. The fancier CSS grid syntax is a good example of CSS that’s awkward to write in JSON. styled-components lets me use normal CSS syntax in a natural way alongside JSX code.
Re:Why I left React for Vue by molszanski on Tuesday December 25, 2018 @11:23PM (#18760499)
What "CSS in JS" you where using before? JSS?
Re:Why I left React for Vue by cageface on Tuesday December 25, 2018 @11:39PM (#18760558)
Mainly I was just using react’s native support for passing styles as JSON objects.
Re:Why I left React for Vue by molszanski on Wednesday December 26, 2018 @12:30AM (#18760764)
Oh. Now I understand. Yeah, that makes a lot of sense.