New Features in Vue 3
vueschool.io
vueschool.io
The Vue implementation seems to ultimately lack this core understanding, and comes off almost a bit cargo-cultish in comparison. React has hooks, so we must have something similar.
I don't mean this as singularly bad, I'm certain Vue can be productive and that this can be a productive feature for Vue devs - but when will we as an industry manage to evaluate software by semantics rather than the syntax we prefer? Does Vue truly offer anything over React that's not in the realm of preferred syntax?
- Vue has a set of core libraries (Vuex, vue-router, etc) maintained by the same org.
- Single file components with scoped styling out of the box.
- Vue integration as a standalone runtime is a little easier than React (unsure about this one).
You can read more about the differences here:
https://vuejs.org/v2/guide/comparison.html#React
I couldn't find any official comparison documentation from the React docs, though.
Honestly I think this is a step backwards. How many components my "component" is built out of should be an implementation detail.
<template>
<!-- A mustache-like template -->
</template>
<script>
// JS, TS, or whatever
</script>
<style scoped>
/* CSS, LESS, SCSS or whatever */
</style>
That components may use other components itself, no part of SFCs disallow that.I've never remotely wanted anything similar to this in Vue, but I have seen what you're talking about used in React, mostly for component wrappers to encapsulate logic. It's not something I like using or seeing but that could easily be swayed by my preference for Vue.
See how it's done in the guide. It wouldn't be as natural as react allows but should suffice for tiny, contained sub components.
https://vuejs.org/v2/guide/index.html#Composing-with-Compone...
But the template string is just a string, right? Can you get the same IDE integration while avoiding SFCs?
This was true of me as well until actually playing more with React. In practice, being able to very quickly extract a child component by just copying a chunk of code to a different spot in the same file is a very nice workflow benefit I now sorely miss when using Vue. In Vue my components tend to be larger and more complex than they are in React because I feel like some small extraction I want to make doesn't "deserve" it's own dedicated file, whereas in React I just quickly make a new function that returns some JSX and I'm done.
The only thing that SFCs do is create a render function for you (as well as some CSS scoping magic). You can do that all yourself and that is all documented and supported behavior.
You have completely the wrong idea here and, honestly, this is all in the documentation.
> React makes no judgements here
Vue typically has fewer opinions than React (and FAR less than Angular) in my experience.
In fact that's what I've encountered in most companies, and what I usually do for my side projects. Basically you output a <app>.js and <app>.css and integrate those in your app layouts / templates.
That's a problem with all these CLI and all those tutorial targeting SPA with a node backend. But IIRC vue-cli as options to help you achieve that, but the docs are not always the clearest for this.
I'm going to try separating the frontend and serving it with nginx instead, and only use Django to provide an API for the DB. Maybe I’ll be able to figure that out. My biggest issue is that there are no decent guides for any of this, documentation is allaround terrible and even if there is some guide, it doesn’t work.
I prefer having the template, styles, and code together, but it isn't required.
My and many others dev environments lean heavily on Vetur and it.. Is plagued with various issues in various releases. JSX/TSX JustWork™ while SPCs are okay sometimes but other times are found wanting..
Is that a good thing?
Yes, there's some obvious copying going on here, but this is not a bad thing! There's been a lot of cross-pollination and inspiration between the major frameworks and ecosystems.
While I haven't deeply inspected the exact details of the new Vue APIs, my understanding based on discussions is that the Vue team has heavily adapted the hooks APIs for a more Vue-idiomatic approach. This includes things like removing the need for the call order limitation, only calling them once on setup, making use of Vue's reactivity, and so on.
Those changes fit well into Vue's stated focus on ease of use and handling a lot of behavior automatically.
This gives the Vue community a chance to benefit from some of the same concepts and improvements that the React team has described for hooks, while staying with their same toolset.
I'm entirely happy with React and have no plans to switch, but there's plenty of reasons for folks to choose Vue (and similarly, each of the other frameworks). I gave a list of some reasons why you might pick each of them a while back on Reddit [0].
[0] https://www.reddit.com/r/javascript/comments/avsuei/react_vs...
[0] - https://vuex.vuejs.org/
I do agree that Vue seems to be reactive in its choice of features, in the sense that it tries to be everything to everyone.
The underlying problem IMHO is that these frameworks are unwilling to create major breaking changes (since that would hamper marketability) so it's easier to just shove things into the unused edges of the semantics space until they becomes a hodge podge of a million ways of doing the same thing.
I feel like Angular is the one framework that sorta "gets it" now. It went all the way to CS lala-land w/ 1.x and rewrote from the ground up for v2 taking several lessons from its v1 and from elsewhere.
Sounds like you want Mithril, but keep in mind that backward compatibility and marketability are, in fact, useful features.
They are (and FWIW, the Stroustrup quote[1] is quite applicable here). I'm merely pointing out that feature creep leads to bloat/complexity which lead to people to complain, and that feature creep also leads to marketability (which is a reason why mainstream language spec documents typically have hundreds of pages). Personally I think this pattern is a problem, but I don't know if anyone has managed to figure out a solution.
[1] https://www.goodreads.com/quotes/226225-there-are-only-two-k...
If "long copy sells" is the reason why feature creep leads to marketability, then maybe an abundance of examples would help.
JS Framework, CSS methodology(UI framework?), etc... or any other perspective you want to share.
What does "actual CS concepts" event mean? This is the first time in my life that I've heard about algebraic effects.
If I am understanding your comments, the implication seems to be react is implementing concepts that elevate the tool while vue goes around in circles to make an alternative syntax.
I don't even agree that the react team has done a good job with implementing a clear concept for their framework. Things like Elm have done a much better job of that. Granted that's a lot easier to do when they don't have to force themselves to deal with js directly.
But even then, why is react implementing hooks not bad, but vue implementing them is? There's a reason why react made the switch, and some of those advantages also apply in vue. These changes aren't just made to follow trends.
When I say "actual CS concepts" I mean things that have been broken down into it's core using a suitable mathematical model. This is ultimately a much more suitable way bo build tools used by engineers.
My personal concerns is that Vue to me is mostly just a reskin with new syntax on things that are already in React. Hooks become the "composition api". Redux becomes VueX. Is this necessary?
Could VueX just have been an alternative to Redux, like MobX is?
Could we just have implemented a Webpack-loader to put styles and react components together?
Some people don't like that React uses `className` instead of class. Is `v-bind:class` and various `@` notations really so much better we can justify a whole new ecosystem?
So roughly - Vue provides fragmentation in the frontend ecosystem. I like competition - but what does it really offer that justifies it? I don't get it, and now what they have been working on is just catching up to React.
But I found JSX hard to read and there was no consensus on how to write CSS and some people were saying that it was ok to use inline styling. WTF? The web design community have been telling me the opposite for years!
Then I started working with Vue and everything fallen in place: no deprecated lifecycles, CSS into style tag and easy to read markup with no Array.map() returning HTML tags.
Fragmentation is bad, but is nice to have a balanced option between extremes.
Arguing that we should pick tools based on semantics without considering syntax is like arguing people should pick spouses based on genetics and not personality.
Presentation is only a small portion of an application. A view rendering engine is required to do a couple of things, accept and render data.
The semantics of how it accepts data enables good software engineering practices like dependency injection and dependency inversion.
The semantics of how it renders data enable ergonomic usage of the renderer (templating, JSX).
Modern web developers tend to write "React" or "Vue" applications - not "Type/JavaScript applications that render with React"
Global objects, singletons fetched from module-powered service locators, unlimited power global stores and enough boilerplate to make the most hardened Java developer confess their sins to Oracle.
Looks like Vue 3 is fine but continues the trend of doing it all.
Let me give you some background about myself - I'm a full time consultant, I write both frontend and backend code for a living. I have worked for almost 27 companies in the last 2 years as a consultant. I have used both.
Vue may copy react, but their implementation and opinionated code structure (Eg. Single file components, Vue-Router, Vuex, etc.) is so much better than the complete freedom that React gives you. Almost all of them who used React had terrible code quality and really bad code organization. In contrast, the Vue code base I've worked with all had some level of uniformity enough for an external consultant to come in and understand what was going in. The worst code I've ever seen till date was on React from an analytics firm. I lasted 15 seconds after which I closed the tab and re-negotiated the contract to do only backend for that firm.
I'm not saying React is bad, end of the day, they're all just tools, but a vanilla TODO Vue application with its syntax is much much better to work with a vanilla TODO react app. Especially for large codebases, this is so true when you work with stuff to manage state like Flux/Vuex.
I also observed that companies using React usually also tend to do more re-writes of their codebases as it becomes unmaintainable over time without an opinionated way to do things like with Vue. Companies with Vue also seem to be more profitable and less reliant on VC money. You can feel free to verify these stats by heading over to LinkedIn/Angel.co and checkout the companies who hire for Vue/React.
So, to answer your question - Does Vue truly offer anything over React that's not in the realm of preferred syntax?
Definitely (as I explained above). I personally would never touch React for a prototype or a project that needs to go to market with less bugs.
These would be almost identical in structure and design. You're drastically overstating the difference between React and Vue.
Aren't hooks only needed because React and Vue still use a virtual DOM?
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?
It doesn't bother me though. Tooling (ESLint or TypeScript) will catch typos, missing methods, etc for you.
Standard HTML, onclick="var++"
`@click="isSomething = !isSomething"`
Tooling also seems to deal with it just fine.
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?
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.
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.
Even with tooling support, those strings still make me wanting to look away...
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?
<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.
It's the curse of the template. Once you have them you inevitably start encoding more of your logic in magic-voodoo template directives.
- 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.
At least in AngularJS I can capture “this” as a closure variable at the start of the component setup “decorator” function, then alias other functions delegated as the component “methods” (event handlers) without worrying about object instance references for “apply” and such.
Now, I can so something similar in Vue components: get the data up front in the event handlers definitions, and delegate to any functions I want using closures or partially applied arguments.
Hard to understate the importance of the new event handler setup API.
Transpilation and static analysis are the ways to go.
I've had my eye on this issue[1] for a while. I'm excited about the idea behind Svelte, but without static typing support, there's no way I could feel comfortable using it on a real project.
GUI programs are inherently stateful and the functional model used by React and others boils down to shoving everything into a giant finite state machine. You explicitly specify all possible states when you code so the state of your GUI is explicit instead of implicit. In traditional GUI terms, immediate-mode versus retained-mode (immediate in the sense of DOM updates, the reference here is how often and how much do you mutate the DOM and not frames per second because the DOM is also stateful which is one of the reasons why web programming require so many hacks). Now this isn't easy in practice because of obvious reasons - the state space explodes as the number of variables increases and trying to having a single store to keep everything in sync can be difficult and annoying. Sure your code will be somewhat more bug-free in the end but you have to spend a lot of effort and end up with verbose code. Svelte on the other hand make variables reactive on the compiler level. So you get both the Excel-style reactive feeling out of the box and at the same time optimized runtime-less code that only mutates when it has to (current solutions all require a library runtime to keep track of things, diff DOMs etc.). In other words, like traditional hand written code but with the compiler preventing bugs due undefined state/variables getting out of sync issues.
My explanation is probably inaccurate/simplified in some aspects so please feel free to elaborate upon it.
I've used svelte for one site that ended up being a good fit. Ended up using Sapper to build out the static site and was pretty impressed with the load times
Have you looked at transpiled Svelte code? It's 5-10x bigger than the source code because an entire runtime library is injected and your code is rewritten to use that library at compile time.
But I worry this will turn into React at some point. Can anyone assuage my concerns on this?
Essentially, they learn from each other, but they will never be quite the same
All of them are approaching the same problem from different directions and paths. If each discovers something new and useful, the others can decide if it would be a good fit for them.
It's all wins all around, so I don't understand the disparagement.
But, my long term view is that Svelte (or Svelte like) library will win out in the long term. Getting code back to basics is a great theme/trend. It's what made me like Vue to start with.
Cost to start. The first time I tried Vue (after trying a bunch of other libraries) I had something working in minutes. React required I learn many other things before even getting a "hello world" to function. Straight html/js connection. JSX is a nightmare.
Integration with existing systems. I work with hundreds of thousands of lines of code in a very messy old system. I was able to gut pieces of jQuery and nearly drop in replace with Vue.
Template focused development. I don't care how super duper awesome the "render" function is. I don't care how fast or performant. I am need to build a tool that I use for a couple of years and then throw away. (long story short, having a build pipeline is a detriment in many apps that I work on because their lifespan is so short)
I may be an amateur, but that is where Vue is genius. I don't have time to learn 20 new entire systems, 10 new build platforms, Node.js (and all that entails) just to get a reactive app to replace some super old jQuery junk.
I am now more capable than before, but after managing so much code for so many years, I want things _less_ complicated, not more. Nearly 100% of the code I wrote 20 years ago is gone now, replaced, rebuilt and redesigned. All the Vue I will build today will be gone in a few years, that is almost a certainty. So I have no budget for messing around.
The list can go on, but I am sure I will get harrassed with this about how React can run live and doesn't need compilation, ha. I tried it, what a mess it was. Learning the quirks of JS is bad enough, learning the quirks of doing 'JS exactly like React/Vue' wants you to? Ugh, that just sucks so bad I want to pull my hair out. The less a library I have to deal with the better. The more pure and simple code is the better. /rant.
Some of the blame rests on the vue team because they did a poor job of explaining the changes. But I think an even bigger issue is that the js community is all over the place in terms of skill level, application of vue and understanding the changes.
The new composition api is basically a way to write reusable code. Mixins also exist, but you can't call code in between other mixins. It also allowed for better typescript support since it's basically regular code and was easier to implement than the class based syntax that they originally planned. It basically killed two birds with one stone.
These changes aren't really big or earth-shattering. They are still an improvement though, and fits well with a project that's making incremental improvements while also being very stable.
I'd love to re-visit that in a couple of years time when it's popularity and community has risen and is more established. Just as React did.
Otherwise you'll be spending far too much time on things that other people have long ago solved in other frameworks.