621 points · by lxm · 8y ago · 374 comments
The reason is that while you may be able to break up your HTML into a composable hierarchy of purely-functional components, the actual data and state you need to distribute to them has a structure that is completely unrelated to how its laid out in the DOM. In a complex web app, a component nested twenty levels deep may need to display pieces of information, like the user's date of birth and the current temperature on Mars, that none of its parent controls cares about.
At that point, you can either bite the bullet and pass state through layer upon layer of props, completely eliminating any semblance of separation of concerns in your component layering, or inject state into your components via some other mechanism, like Redux/MobX/Context. At which point, JSX is basically just another fancy HTML templating library.
"Idiomatic" React is a fun game to play when doing basic examples, using something like a todo manager, but as soon as you're in the real world, you hit its limitations very quickly.
Sadly it seems that's mainly been cargo-culted. It's not the case that React+Redux is the equivalent to say Angular, but by some unfortunate accident due to Facebook's announcement of Flux, and then the hype around Redux as a 'better Flux', people started assuming React+Redux is what is needed to build a React app.
Meanwhile Dan Abramov, Redux creator says [1]:
> Flux/Redux is meant for big apps with complex nested UIs that have many independent parts but share common caches of data.
That's not "every semi-complex React app". In most "semi-complex React apps", most state can be derived from the route (e.g. react-router) or is relatively local. Redux is not required.
[1] https://twitter.com/dan_abramov/status/732719257579065345
As developers we can't all be building tools. We choose tools that others build for us, so that we can get our job done. Soemtimes I'm interested in going "one layer down" and build tools, but it's almost always a distraction; we want off-the-shelf products like React and Redux. We need to pick stable tools that promise some sort of longevity. We also need to pick tools where best practices and idioms have been established.
To do this we have to trust someone else's opinion and try to gauge which solutions have the best prospects. This means not just evaluating software based on its own technological merits, but also listening to what "the community"/"the industry" seems to be rallying around; you don't want to be stuck using a library that nobody is maintaining, just as you don't want to be stuck using something that's just badly designed.
When we started using React, there was no state management framework available, and everything was handled somewhat ad-hoc. Then Facebook described Flux, and we realized they were onto something, so we started using their patterns, with some simplifications where theirs seemed overly complicated. Then Redux came along and seemed like a better way to do things.
At each point there was uncertainty about what best practices and "idiomatic" solutions would turn out to be, because the technology was immature. I don't think anyone was cargo-culting. It was just that a lot of people were busy trying to create things, and when there isn't clear guidance, and the alternative is going back to Backbone or jQuery or something, then you just forge ahead, trying to do fit the pieces together.
IIRC there were a lot of comments about having to pass props to children constantly (without using a state management library). Seems like it's a lot easier to not use a state management library now that an official, non-experimental Context API exists. But remember, this was only added a few years later.
It took me many years to realize this. I think very few front end developers understand this. And more problematically: very few framework devs seem to understand it.
Stated another way....
Your tree of UI widgets, and
Your tree of data which feeds those widgets
... are two orthogonal trees.
If you are a front end dev and you haven’t spend time wrestling with that, I strongly recommend it. It’s extremely likely your front end architecture is suffering because of it.
React take the strongest stance on this matter, by making the interface to every widget be one giant shared global. But globals are bad, so while it’s good they acknowledge the situation, they mostly punt on the question of how to deal with it.
>Your tree of data which feeds those widgets
Not with a well-designed XML format and XSL-T! But hmm, nobody seems to use that anymore either.
One thing to realize is that you always get to decide on the granularity of your compositions. It is not necessary to build a deep hierarchy if you design the granularity of your interfaces correctly. Another great tool is higher order functional programming, such as passing components to components (via children). In this way, it is easy to describe generic interfaces and supply specific pieces of data without having the intermediary interfaces know or care about that data. Another approach, akin to using something like the state monad, is to use Reacts context feature, but this is rarely needed, in my experience.
Personally I make heavy use of higher order components, and I find I rarely exceed a component tree height of three.
Right now with a few devs it is going very well but I do worry about on-boarding people who are not proficient in functional programming.
React code without a global state management library is very pleasant and easy to read/understand for many, but for some it is not always obvious to write. You may have to spend more time code reviewing and training newcomers who will sometimes feel like their task is impossible without Redux. I have yet to see if those requirements can still hold for a big team but I think it is possible.
My current opinion on Redux is that it is best suited for existing project migrating to React because you may inherit very odd relationships between the view and the data and Redux will avoid you a lot of pain on this regard. A new project should avoid Redux & co as long as it can.
That's my experience as well. If you use a deep component hierarchy you have bigger problems than those solved by Redux, VueX or the Context API.
Higher order components or even simple functional components are really underrated when it comes to making your application simpler to reason about and to maintain.
> At which point, JSX is basically just another fancy HTML templating library.
JSX is optional syntax sugar; my team uses React and Redux heavily, but we've opted not to use it.
HTML templating is great actually, all the rendering is data -> UI.
If you go back to the early Rethinking Best Practices presentation[0], it boils down to asking why client side development isn't like like HTML templating. The answer is that updating the entire page DOM on every change is unworkable, there needs to be support for partial updates. That's what React offers, a return to the data -> UI paradigm, without having to write a secondary code path for partial updates.
Having a shared store really does change the way you look at web apps - it's almost a completely different paradigm. If you can avoid re-loading the data for a view if you already have it then then opening a new view to edit a subset of the data instead of dealing with popup makes life so much easier - you get a lot more freedom with the UX and going back to the previous view with the parent data is almost zero-cost.
The vast majority of our codebase is comprised of simple idiomatic React components. Our reducers and glue code (e.g. @connected containers) are a very small portion of the codebase. If I woke up tomorrow and decided Redux was the source of all our problems I could completely remove it while only needing to refactor a small portion (<5%) of our codebase that's mostly boilerplate anyways.
I don't understand your point that injecting state into your components (e.g. with Redux' connect function) means JSX is just another fancy HTML templating library. All you need to do is have your React component export a "dumb" version as well as a connected version. Your dumb version will still be reusable in other parts of your application, and any other application could also use your dumb component and connect it to their global state through whatever means they please.
There's your problem I think, as other sibling comments pointed out.
I understand that such an open-ended product is frustrating to use because redux is insanely overengineered, mobx reintroduces data binding, and context is buggy and terrible, but I don't think what you're calling "idiomatic React" is actually considered idiomatic by anyone, including the core development team.
It’s easy to point out frustrating things or hard problems; it’s not easy to point to a way out.
Personally I love the explicit state flow react forces, and I would hate to move to a framework where I spend time figuring out how data goes from point A to point B.
Redux is what you get when people try to use React as a "full-app" framework instead of what it's meant to be: a view layer.
Is Redux not exactly that?
Ironically, Redux came out around the time Angular popped. While not everyone, a significant portion of early adopters came in because they were rejecting the Angular 1.X way of handling state, and Redux was the polar opposite.
Isn't a good chunk of AirBnB, Facebook, Instagram, Netflix, The New York Times and Dropbox written in React?
The built-in state management has limitations, of course. I see it best for keeping state relevant to display-- React is supposed to be a "view" library, not a state management one.
Because React = state to DOM while Redux = how to get from previous state + action to a next state? :)
They do different things.
So e.g. if you want to have a Leaflet map i.e. `this.map = L.map(...);`, Vue will automatically add reactivity to this property. Sometimes I had big problems with this behavior (or it was simply annoying), so I wrote vue-static based on ideas of the core developers:
https://github.com/samuelantonioli/vue-static
Now I can have big objects in the Vue component which don't get automatically tracked using the reactivity system.
- - -
A problem for many beginners:
Another problem with the reactivity system is that sometimes you have a route like `/employees/:id` and edit an object. But on abort, you want to rollback. One thing you always have to do is to copy the object you want to edit (I use lodash's `_. cloneDeep(obj)` for this). If you use Vuex, it's not such a big deal because it works using immutable state, but when you work with a plain javascript object this will definitely generate some headaches.
- - -
But otherwise, I think Vue is definitely the way to go. `v-model` can be seen as syntactic sugar while you have to add it to react inputs and textareas manually (using onchange and setState).
You can write stateless Vue code just fine and use JSX. On the other hand, React misses some of the cool features like the Vue component files (.vue files) and its templating language. And the best is: The framework doesn't say that you have to use it. It's not so opinionated but still feature-complete with the official plugins.
React is just JavaScript and HTML.
I personally find Vue templating syntax much easier to follow than JSX, but that's because I'm used to it. I honestly believe that's how React users feel about JSX too.
This is patently not so.
Vue has:
- three different html-like attributes
- three different scripting languages in templates (two Javascript-like, one Javascript, but only expressions)
- one scripting language for controller/model which actually breaks JS assumptions (about what `this` is, for example) by magiacally hoisting some (but not all) properties of an object
At my last company we used `react-hyperscript` which was a simple wrapper around `react.createElement`.
Ultimately, the React developers made the mistake of making `createElement` so annoying to work with, I assume because they bought into JSX. Granted, JSX might have been necessary when React was first created in order to ease people into transitioning to HTML in JS, but I feel like we can move passed that now.
I highly recommend `react-hyperscript`: https://github.com/mlmorg/react-hyperscript
A translation from the JSX example that was the first (only?) example on the React homepage at the time:
https://github.com/jasom/parenscriptx/blob/master/example/co...
Furthermore, Elixir has Agent, a higher abstraction on top of Erlang/OTP gen_server that's easier to grok and use in many simple cases with no need to separate the public interface and OTP callbacks.
I think this is what the Flux model is all about, making UI code actually be a pure function of state. By that, I mean literally a function, where state is the argument, and where all you render depends solely on said argument.
If you want to change what is rendered, you send a message and a Store deals with the state modification. Once it's done, it calls your pure function again, this time with a different state, so you get a different render.
This IMO, decouples state and and view instead of tightly coupling it. Redux is the best Flux implementation to demonstrate this IMO because it puts all state in a single Store. The messages to this Store can come from anywhere: UI, server, me typing on the console, etc. The state changes independently of the UI and in fact I could have a full application without having a UI whatsoever. Or I could have a UI without knowledge of my state's topography, because Redux lets me morph and cherrypick my state before I pass it to a component as props.
I think that's a good exercise: to try and build an application thinking of it as a series of actions on state first --and then how that may play onto UI-- to get to appreciate functional components. I'm curious to know why you think why you think Redux only "pretends" they aren't though. (:
Also, conceptually, you often have a lot of state that's very directly concerned with and specific to the UI, and isn't just idyllic, agnostic "data". Things like "is this menu open or closed?" and "what's the current string value of this input (which isn't meaningful until the form is submitted)?" In Flux, those things tend to add a ton of boilerplate in terms of change actions, and split tightly-related concerns into separate corners of the codebase (if I remove this menu component I have to remove its open/closed state variable and the corresponding action).
To be sure, there's not really a great way to decouple things in the reactive architecture. I personally lean towards stateful components that are decoupled at their boundaries instead, which does carry its own downsides. The only solution I've ever seen that truly felt right was two-way databinding, which Vue (sort of) still has, but which has fallen out of fashion in general because it requires "magic" and because it tends to come with performance costs.
The author is wrong. Vue doesn't have two-way binding. It has one-way binding with events. Components can't force anything upon their parent's state with an event.
> "You can use the v-model directive to create two-way data bindings on form input and textarea elements. It automatically picks the correct way to update the element based on the input type. Although a bit magical, v-model is essentially syntax sugar for updating data on user input events, plus special care for some edge cases."
I'm not knowledgeable enough on the matter to say if this is or isn't, and to compare vs Angular, etc. But don't blame the author for this one ¯\_(ツ)_/¯
All props form a one-way-down binding between
the child property and the parent one: when the
parent property updates, it will flow down to
the child, but not the other way around. This
prevents child components from accidentally
mutating the parent’s state, which can make
your app’s data flow harder to understand.
https://vuejs.org/v2/guide/components-props.html#One-Way-Dat... AngularJS uses two-way binding between scopes,
while Vue enforces a one-way data flow between
components. This makes the flow of data easier
to reason about in non-trivial applications.
https://vuejs.org/v2/guide/comparison.html#Data-binding <Component v-model="foo">
is basically shorthand for <Component :value="foo" @input="foo=$event">
In particular, the child can't affect the value of the parent's "foo" attribute except by sending an event. This is in contrast to Angular 1 where changing "foo" in the child would also change it in the parent, which would often lead to confusing data flow cycles.As other people mentioned, Vue indeed doesn't have two-way binding, and v-model doesn't have the pitfalls that Angular had. It is just syntax sugar.
Maybe it's about time Vue people remove the mention of two-way binding from their websites, since it is being used to attack the framework. I've seen that in other discussions here in Hacker News.
https://reactjs.org/docs/components-and-props.html
The best thing to do is just to brush up on functional concepts, thinking about things in terms of composition and application, and threading state through your application and flowing back through to the top via dispatches. Learn more about flow (the concept, not the framework). I like to picture a waterfall, where the water is state that always keeps flowing no matter what it hits. State should start at the top from some source, we don't care what that is, and then flow through the application down into the leaves. Functions can do transforms and reductions on state, but they should never hold on to state the way class components do.
In the last SPA I wrote there's about 100 components, less than 5 of them are stateful.
- The reason the API call is made at `created` lifecycle is that the video is a quick, 5 minute intro for beginners. Beginners, as in "people who are familiar building static websites using html/css/js". There is no need to bring in Vuex or vue-router yet. In fact the whole beginner example can be put into a single HTML file by including a Vue script tag. The approachability is what made Vue shine. Some other frameworks assume that you want a build tool, state management, client side routing etc and beginners spend hours configuring those tools and figuring out state management and client-side routing, instead of doing real work.
> To answer to my initial question: API logic should not be written in Vuex nor in components. There is even a good example on how do that in some of the official code examples.
- The example[0] clearly has the API logic in the Actions. The `/api` folder is a mocked API for illustration purpose.
[0]: https://github.com/vuejs/vuex/blob/dev/examples/shopping-car...
Okay, say I do the tutorial and build a simple page - how hard is it to retrofit routing or whatever to it? A lot of the time with new frameworks, if I get past the initial setup hurdle, I can't work out how to easily move away from toy apps to something I can use in production.
Example 1: A great typographer, Wenting Zhang, author of Type Detail[0], contributing to Source Han Serif, learning Vue to do some interactive widget for variable fonts[1].
Example 2: Brian Terlson on TC39. He's using Vue without Vuex or Vue-router to build an app to track TC39 discussions[2].
I hope we can admit that many people might not need store and router[3]. Store and Router are necessary for building complex SPA, but don't make them necessary, as many don't want complex SPA. They impose learning efforts in exchange of better architecture, but the imposed effort might not be worth it for many people who just want some data-rendering, some reactivity and some interactivity on their websites.
[1]: https://twitter.com/DesignJokes/status/1015003288528400386 and https://twitter.com/DesignJokes/status/1014260361535647744
[2]: https://twitter.com/bterlson/status/913433979239436293 and https://github.com/bterlson/tcq
[3]: https://medium.com/@dan_abramov/you-might-not-need-redux-be4...
Previously on vue-cli 2.x, it was just a question on the project initialization step.
This clearly outlines a suggested structure for non-trivial apps, where API requests are separated from the state management. It also references the Shopping cart example as a guide.
Due to this glaring oversight I can't see any criticism the author has as valid in the section about "Unclear architectural patterns".
TypeScript support is mediocre. It's supported (Vue will let you use anything) but it's clearly a second class citizen.
There's also no real accepted best practices, which the author touches on (where do API calls go). Third party component design varies pretty wildly. I think this is just the reality of a young framework casting a wide net, we'll see what the future brings.
It's not perfect, but like the author, Vue was a great decision for my team.
Will be using TypeScript. For internal implementation only. Does NOT affect ES users, but should improve TS integration for TS users.
I wasn't aware that vue3 was going to be written in Typescript - that is very welcome news.
Changes that break backwards compatibility are reflected across all three at the same time, and the correct versions are installed by vue-cli. I had several starts with react, react-router, and redux, and on almost every occasion something from my last attempt was broken because the api had changed, and the documentation changed with it (in the span of 3-4 months). That lead to several WTF moments. IIRC there was a period where react-router made some breaking changes from v2 to v3, and then less than a year later made more breaking changes for v4.
Vue is also a lot simpler to drop into an existing application. The .vue single-file component is very approachable, albeit a bit magic but about as magic as JSX. You can add a vue-loader for sass/less/etc. and simply specify lang="less" in these as well.
Vuex was a little easier for me to grok, although I had the advantage of trying out redux first. It has the advantage again of sharing documentation with the rest of the project.
Also, because react has worked for big companies as you mentioned, does not mean vue couldn't work for them as well. React gained a lot of momentum early among western programmers. Vue first gained traction in Asia - Evan You, the creator of vue, is from there. Also you might remember the massive amount of confusion for early React adopters regarding how to manage state. People liked react, but it only really had the view part ready out of the gate. Facebook's explanation of what the early-best-practice flux model entailed was vague, and there were several slightly different implementations.
I remember working on Angular 1 projects, where literally everything from loops to http calls was mandated by the framework. Then everything suddenly became legacy. Angular was going to be completely rewritten, and everything I had learned was going to be tossed away. I still, to this day, have to work with projects that are Angular 1 code rot hell.
I think that's probably why I have never had the problem's you have had, because I never wanted to use React Router or Redux. Those pieces of functionality were easy to implement on my own. (Redux itself is incredibly small)
Personally, I think it's silly to use Vue. Angular had serious deficiencies and project mismanagement, and React was a real solution to those problems. I mostly hear either minor grievances from the Vue crowd, or no response at all as to why they switched (hype train most likely).
I also don't think Flux was vague, it just lacked an implementation. Again, there just seems to be a big fear in the JS community about writing code instead of pulling in a framework. React itself is just reactive functional programming. The sell of not writing it yourself is that you get to work with a nicer API while the React team improves the backend for you (a la Fiber).
The JS ecosystem really has a problem with bloat in my opinion and Vue trumps React in the regard (react eject anyone?).
My cofounder suggested I check out vue for the rewrite of our legacy project, and I was able to onramp SO easily. I can easily hand off components to other team members to write, and it rarely broke stuff in the rest of the project. On the whole, vue feels a bit less powerful but a LOT simpler to wrap your head around while subscribing to the reactive UI paradigm.
I'm curious whether Facebook actually have any endpoints where exceedingly fast rendering is necessary because it'd be the bottleneck. Facebook tends to be really slow for me but I figure that's down to it being really slow fetching data.
We've built our single page application (SPA) web app with vue.js and are very pleased with the results -- https://checkoutclip.com. We were able overcome most of the stumbling blocks by looking up https://vuejs.org/v2/guide/, https://github.com/vuejs/vue/issues and https://forum.vuejs.org.
For server side rendered (SSR) pages, we're using nuxt.js, which is working out great as well. E.g. SSR page: https://video.checkoutclip.com/-LDQ5TtL_yywYCgUNb6K
I would recommend vue.js for anyone building their first SPA even if they don't have prior experience building one...it's easy to pick up.
With that said, the new vue-cli uses Webpack 4 now which can do code splitting, and you can code split on route also to make individual page bundles smaller.
Saving the site on the hard drive gives me a wooping 10Mo for a home page. with a menu, a few pictures and some text.
This is insane.
vue is used only for the web app. No js frameworks used in the chrome app.
If JavaScript is disabled I just show a message saying the site needs it.
I also only support modern browsers and haven't had a complaint for 3 years.
About 3 months ago I completely dropped support for any browser that doesn't support CSS grid (no more IE 11!). Again, no complaints. This one is more "brave" but I use Modernizer and show a clear message outlining all the required features the user's browser doesn't support and why they would want that feature in a browser. There's a link to a website to help them find a modern browser on their platform.
Edit: I realised that based on what I said you could argue that users are annoyed but I'm just not aware. I doubt this is the case since the users are keen and vocal. I get messages almost daily from them telling me the features they want to see. The last time this had to do with browser support was one message 3 years ago about IE9 not supporting the TLS certificate or something. They were forced to use IE9 at work.
> The single best improvement I've made to my mobile browsing experience in years wasn't getting a new faster phone, it was installing Brave and disabling javascript. [1]
To be honest, (s)he was right. But at the same time, it's disgusting, and plainly bad, to see how much of the Internet is _broken_. Which by my definition means requiring JS even to show some text and images on a web page.
I understand that more advanced features might require some scripting, but come on, I'm pretty sure that's not the case for printing some good old letters and pixels on a browser window! And still, lots of places seem to not know how to do it without dynamic code all around. (I'm not talking about this specific site, in any case. Just felt like ranting.)
https://en.wikipedia.org/wiki/Fault_tolerance
Progressive enhancement:
Then please have a noscript tag.
> Serious question: is it common for folks to disable js?
That's not the only reason you'll find for JS being unavailable.
Windows Updates has managed to disable JS in various situations across both Edge and IE over the years due to tightening security policies.
Chrome has had V8 crashes over the years, as has Firefox.
The browser might be misbehaving, but rarely will the user attribute it to the right place - your site will get the blame.
JavaScript-only is not friendly for SEO.
I'm also not familiar with vue so I was trying to work out if it was used to build your web page or the actual chrome app. The web page is fine but I just wasn't sure where vue came into the picture for such a simple site.
There are some things I really, really hate about React. It is not kind or accommodating (Vue is both of these things), but it gives you control. I was head-over-heels for the first few days of using Vue; "breath of fresh air" is exactly the phrase I'd use. But the project I was using it for was an IDE of sorts, and eventually I just needed more control than it allowed for.
If someone told me they were going to build a basic website - not a web app - with React instead of Vue, I would laugh at them. Vue truly is a successor to jQuery for the reactive age. But for really complex applications, it's too "magical" in my opinion.
Mithril.js is a framework that is truly "magical" in my opinion. I mean its 8kb, includes routing and XHR Utilities out of the box. Faster render times than Angular, Vue and React. You can write HyperScript or JSX. The syntactic variants allow you to write your components as ES6 Classes or closures. Lifecycle methods, a render and mount option and the list goes on and on. People tend to dismiss Mithril because it's a lesser known framework but it has a vigorously thought through programmatic approach and you've got a direct line with the maintainers, you cannot match that.
Sure, each to their own but calling Vue "Magical" is an incorrect assessment.
When I ran into an issue using React, tracking it down was extremely difficult (by the end it was just "difficult" due to improved tooling around react). Mithril is small largely because of its simple implementation, which makes debugging a joy.
1: They seem to mean magical in the sense if "I'm never going to understand how it works"
With ember you got controllers, models, inheritances, many special methods...
The VueJS documentation also makes it easier to get in. The Ember beginer tutorial starts with a full fledge app with a cli to install and use and features routing and addons O_o
How long have it been since you at least looked at Ember?
> With ember you got controllers, models, inheritances ...
You use those now only when you choose to or not at all.
> ... many special methods
= adding features Vue does not have.
> The Ember beginer tutorial starts with a full fledge app with a cli to install ...
Ember-cli is something everyone is desperately trying to copy. Even Vue!
Sorry, but this sounds like generic anti-JS-hate: tons of misinformation to bash something you have no clue about.
All that templating and two-way-binding stuff.
Sure, Vue goes a bit more in a lean direction, because it doesn't offer as much out of the box as Ember, but the idea behind the components seem to be similar.
React or Angular (>2) have entirely different approaches, from one another and from Ember/Vue.
They felt fresh to me.
I kinda like this syntax, when I first learned vuejs I knew immediately that some magic was going on in the background. If I saw marko's syntax I'd be wondering how this shit is getting done. It also makes it easier when searching for issues or suggestions. "vuejs computed property" vs searching generic terms.
>Chat based community
This part is simply not true, there's tons of individual vuejs communities all pretty decent. Shoot me for saying this but laracast isn't a bad option for Vue help. Everytime I have an obscure problem I find a solution on there.
>The reactivity system will only track changes under certain conditions. Don’t expect to throw anything you wish at it
This is the one part I hate about vue.
>Does this mean authentication logic goes in Vuex too? Will a state manager start mediating all application logic now?
Been there done that. I typically use vuejs for lightweight applications solely because I do run into this issue.
What tutorial are you using? How old is it? What didn't work?
https://www.adcisolutions.com/knowledge/how-build-single-pag... https://codeburst.io/full-stack-single-page-application-with...
The first one doesn't build, if I remember correctly, and the second doesn't display anything after about the halfway point. I'm running them on MacOS.
I tried a couple of others with similar issues, but didn't save the URLs.
Vue 2->3 won't be so bad because they're promising backwards compatibility.
>This is the one part I hate about vue.
Haven't used Vue for a while, but if I recall correctly it will only track changes on keys defined in the original data object. Is that what you and the parent are referring to?
Don't know how vue compares with this but for angular beginners this is a very common mistake.
The quality of answers were so low I found myself longing for the days of expertsexchange.com.
Why did laracast get so popular for Vue? What was wrong with Stack Overflow?
Then the Laravel ecosystem adopted it widely, and a good Vue.js tutorial series was published on Laracasts (which also happens to host the official Laravel forum)
Hence the close link with Vue and the Laravel community.
I dislike that Vue feels too much like Vue and its magic and not enough Javascript. With React I feel like writing normal ES6 Javascript.
I love the official Vue documentation and examples.
I am a bit cautious about the ecosystem surrounding Vue. About a year ago when I looked at various interesting projects/tools extending Vue it seemed most of them were in China with very limited English documentation.
Finally the job situation for front-end work. In my region it seems to be about 75% React/20% Angular/5% various(Vue rarely mentioned)
> This trend of using chats for questions is plaguing open source projects and I think it needs to end. There is no collective learning anymore.
This is a very important notion not least of all from an archival pov.
That's basically Reddit
I don't know how many times I've found answers for versions of my libraries/toolkits that are so old that they're useless. There's little point these days in persisting answers to questions about Node 0.4.0, for example - and that's only ~7 years old, downright modern by some viewpoints.
For me personally it took the MVC into SPA territory, got rid of all the muck that's jQuery and replaced it with a fun, easy to design UIs with platform.
If you ask me it's biggest achievement is that it put design, experience and interaction on the same level, literally - thanks to .Vue files :) Consolidating them just made sense.
Ok, but where's an example that shows how this backfires? Why should the API logic not be written in Vuex?
One more thing I think deserves mention: Vuetify - Vue's material design component set. It's being used in the project I'm currently in and I worked with Angular's material design component set and I have to say the former is way better built.
(Author here. I didn't really expand on that because the article was getting pretty long already.)
For example, think about authentication logic.
It involves more than just calling the API. Eg: extracting the JWT, saving it to localStorage, decoding it, maybe checking user roles, etc.
If you do that kind of logic on Vuex actions then these will start being responsible for a lot of your application. If you are fine with that, by all means, use Vuex actions to do (a lot of) stuff not really related to managing state.
Personally I don't think it makes any sense to delegate that kind of logic to Vuex in the same way I won't use Axios for anything other than making HTTP requests.
There are also practical aspects. Vuex actions need to have a very particular signature, since you never really call them yourself. To me that was the final reason for moving a lot of logic to their own modules.
In my latest projects I've almost stopped using Vuex actions altogether and it feels really good. Authentication is not managed by some parts of Vuex, but by my own auth module.
It then has some getters which just get the state from the store, but the actions call to a separate module which manages storing it in LocalStorage or making the http requests.
Works for me, but I just took what I learned (Vue) moved it to when I learned a year later (Vuex), when things became complicated in Vuex I just moved the complicated bits back 1 bit more and everything became simple again (which seemed like the logical thing to do).
Although at this point in time it is pretty cumbersome to get the entire Vue stack type safe. I think it's getting better but it's far from ideal. You'll need a wide range of libraries to get everything set up. For instance here's the list of libraries I use for bootstrapping projects:
Vue-class-component - Vue-loader - Vue-property-decorator - Vue-template-compiler - Vuex - Vuex-class - Vue-router - Vuex-router-sync.
The ecosystem just keeps getting larger and larger and for a beginner it can seem pretty daunting. I don't complain though - UI's have become a lot more technical and complex the last 10 years - and of course that'll increase the learning curve of learning how to program them.
I have worked with multiple Vue projects now. The time is spent about 50/50 in pure development and getting the build setup working correctly.
Better pick another tool to do the job which has mature integration with build tools.
Granted, the reason it works well for us is because we started out right by looking at existing templates using Vue + Typescript which probably saved us a lot of hassle. The wrestling with configuration switches was by and large already done for us, but having used this combination extensively now I can say I'm familiar with all configuration matters in our projects and I find none of them particularly poorly documented or obscure.
I really like Vue for the many great strong points it offers. But I'm equally ready to completely ditch Vue for its complete and utter garbage with respect to build/debug configuration.
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
Production version: <script src="https://cdn.jsdelivr.net/npm/vue"></script>
If you need something more complex, vue-cli has webpack inbuilt: vue init webpack my-project
cd my-project
npm install
npm run dev
Or if you need webpack, but not the complexity, swap the word 'webpack' in the above command to 'webpack-simple'.... Vue has already done the hard work of getting the build apps configured for you.
Probably, but Vue only officially supports Webpack or Browserify.
For all things more complicated and that require intelligence to think about good architecture and how to structure state, the magic of Vuex won't do the job for you, and in fact it will hinder you from doing it. React doesn't have these limitations.
Also, the community on Discord is not friendly, in fact the community and the limitations of the framework are quite similar, they're all "write a todo-app like the tutorial, or I won't be able to help you".
Can you elaborate on that?
I disagreed with the "unclear architectural patterns" -- I've found just writing Vue components that function as Services to hold all that kind of logic more than adequate, and have never really needed to follow the Flux-ish/Vuex approach. 90% of the time all you're doing is making web requests and possibly displaying data or results to the user on the frontend... If you're clever, you're doing a little caching and figuring out when to perform remote fetches, or storing stuff in local/session storage.
I think Model-Service-View frameworks are the (minimal) future, where you just pair a view library with a data management component (something like Backbone, if not Backbone itself). MVC was the dominant paradigm (angular 1 days), then MVVM made an appearance (knockoutjs), and now MV-? where the ? is some event-driven system or flux/vuex style system. I think abstracting to Services allows flexibility at the model-management layer -- if you want your services to send out events (and wire up your components to listen), then good. If you want them to have promised based interfaces, that's fine too.
I tried out knockout's components way back when I saw the blog post[0], and they were pretty nice.
[0]: http://www.knockmeout.net/2014/06/knockout-3-2-preview-compo...
Surely there's better ways of doing ReactJS rather than lots of setState? Of course I use setState but try to avoid it generally.
And I almost never, ever use bind() - don't es2015 fat arrows make it obsolete?
Otherwise, yeah.
But I guess old habits die hard...
(Disclaimer: I use React/Redux and not Vue/Vuex, but I think the above applies equally to both.)
That then leads me to my next question though, if I am using Vuex to abstract the API calls is it bad practice to use Vuex actions for API calls that don't need to be saved into the store?
Then api.fetchFoo(bar).then() mostly does it.
Benefit is separation of API from component.
Sounds like he wants a convention over configuration framework from a barebones DIY from the ground up style framework.
I guess Ember and Angular are more of one-stop-shops in that way.
There's nothing wrong with using chat for collaboration and support. However, using a proprietary platform like Discord for this purpose a braindead move. It's astonishingly dumb to do this.
Listen, IRC is not sexy. But it works, and has been chugging along for decades now - in the same time that a few dozen proprietary chat platforms have come and gone. It's supported by dozens of open source clients and servers, has integrations with all sorts of bots and git and ticket trackers and such, there are dozens of libraries for working with it, and networks dedicated to open source projects. It's a no brainer.
The particular issue called out in this article is trivially solved on IRC. There are a half dozen ready-to-roll public IRC log softwares, and most of your users have clients which are automatically keeping logs that can be restored from if there's ever a service outage on your logger. Hell, if you send me an email I will put my IRC client in your channel and publish public logs for you for free.
React and Vue basically manage state the same way, which is 90% of what you'll be doing in these libraries.
And just like in React, default state management is insufficient in Vue.
That hasn't been my experience at all. The medium-sized app I worked on used what is apparently called the "store pattern": a state class with data and methods that mutate it, and components that read the data but only update it by calling its methods. This provides the major benefits of Redux ("functional" components whose only state is purely local) with much less complexity.
Oftentimes beginner would create just a single React component that references the state - which immediately couples the visual parts of your Application to your data, making it harder to introduce automated testing later on. When using the smart/dumb pattern together with react-redux it is very straightforward to come out with a good architecture, that does not mix ui and business logic/data handling.
For example, I wanted to have a UI that was rendered based on the JSON payload that would get committed to a Vue Store. I consistently ran into issues where Vue would complain about the client rendered code differing from the server rendered code.
Are there any js frameworks where you can specify which components are rendered on the server and which are clientside?
https://blog.strapi.io/cooking-a-deliveroo-clone-with-nuxt-v...
I want to be able to have essentially have everything server rendered with reactive views. Not sure if there is anything that supports that, but I feel like that's how a SPA "should" work to an extent.
Also, what gets really weird is if you are trying to use environmental variables. The solution is to inject your environmental variables into the client (https://nuxtjs.org/api/configuration-env/) which is what I want to avoid.
I can do what I want to an extent with Ruby and Sinatra, I just want to avoid setting up webpack and babel for getting the reactive components.
https://github.com/egoist/vue-no-ssr
Regarding the "client/server render results do not match" issues: Fixing these is mostly easy in my experience, especially since vue will log the offending dom nodes to the dev console.
My challenge is that I don't want everything to be rendered on the client. I only want very specific things to be client rendered and nuxt does not have a way to do this (I think).
The no-ssr thing is the opposite of the functionality that I would like. I want to have the ability to declare which pieces are only server rendered and sprinkle in in client-side rendering where it makes sense.
All my similar issues went away after discovering that.
[0]: https://github.com/vuejs/vue-class-component/blob/master/REA...
The author refers to the shopping cart sample -- which is exactly what I used as a blueprint. I think that's acceptable that the design pattern suggestion is coming from the store layer vs. the template layer (who is focused on the UI/UX).
You have one component with data. You may bind it do a template. You insert it in the DOM, or in another component, and if the data changes, everything rerender automatically.
That's it. There is nothing more to it.
Their reasoning for why surplus uses real dom nodes seems pretty solid[3]. My oversimplified TL;DR: a virtual DOM mainly solves the problem of JavaScript not being reactive; the DOM already is. So if you have an efficient general solution for adding reactivity to JS, the need for a virtual DOM is reduced as well, and removing it then saves on the performance / complexity / interop overhead that it would add.
And S.js looks like pretty sweet reactivity library, even without surplus - lots of fine-grained control options too.
[0] https://github.com/krausest/js-framework-benchmark
[1] https://github.com/adamhaile/surplus
Oh? I've only ever been in the gitter room... I had no idea there was a discord too...
- why ever choose Vue over a minimalistic React setup?
I mean, yeah, when people say "React" they mean "Reach + a ton of other heavy complex stuff", but core react + redux seems even more lightweight than Vue. Or you'd just choose Vue to keeps way the "React gurus" that would come in and overcomplicate everything? :)
React achieves much more with much less.
Rubs me the wrong way. Better performance is always a net gain, and a high performance website provides miles better UX than the same website with waiting all the time.
I think that's easily disputed: it's always a trade-off. A 0.001 ms improvement in performance is a net loss if makes code 10x less readable, because that means programmers are more likely to introduce bugs, which would be a net loss. For example, I one worked with someone who changed all i++'s in a codebase to ++i's, even though they were not in performance-critical codepaths. That was not worth the effort.
It's 2018, we're all walking about with supercomputers in our pockets, and yet we're putting up with <60FPS UI.
The impact of UI performance on user experience is serious enough that Netflix wrote their own rendering engine. https://medium.com/netflix-techblog/crafting-a-high-performa...
> I one worked with someone who changed all i++'s in a codebase to ++i's
Did you use the previous value of i, or did you just intent to increment it? ++i communicate that I'm not interested in the old value, where as i++ does the opposite. I actually use it as such, because my intent to a future reader of the code is more clear.
That said, for complex types, and with "stupid" compilers ++i can absolutely be significantly faster.
I would consider that a valid reason to use ++i. In this case, however, he indicated performance as being the reason. Furthermore, this was for a school assignment demonstrating that we could properly implement a particular algorithm, so the performance difference was absolutely irrelevant.
I think Vue is great for smaller projects and would absolutely recommend it.
Vue 3 they are moving to TypeScript:
> Will be using TypeScript. For internal implementation only. Does NOT affect ES users, but should improve TS integration for TS users.
I know of two ways in vue to do this and both ways either completely break or make modularity awkward. The first way is to signal the parent with emit. This ties the parent object to a signal and if you want to pass info even further up past the direct parent you have to have components explicitly pass that signal up. While this doesnt break modularity it absolutely makes it awkward.
The second way is to use vuex as a global. This breaks modularity by immediately tying the component to a global. Vuex makes things easy but breaks modularity completely as soon as a component refrences vuex.
I understand why things were done this way. Essentially it's done to prevent a certain class of endless looping bugs but there has got to be a better way.
Can you explain a bit what you mean here?
I haven't used vuex yet, but to use my Redux/React experience as stand-in: the channel to emit data changes through is passed as a prop as well, so the component is still "modular" in that it is not hardwired to redux (or, presumably, vuex). Since it has to connect to the outside world somehow, that can't be the criterium for breaking modularity either. So I don't see where the modularity
Having the data in a Single Source Of Truth seems a sensible reason to store it globally as well.
(aside: elsewhere here I discovered S.js, a reactivity library that looks really interesting. Perhaps using something like that to make the data reactive to UI changes is what you're after?)
Any time you have something reference a global it becomes tied to that global whether it's a function, component or something else. If I want to take that component and move it to another project then I have to take that global and move it along with the component. That is a form of broken modularity.
Passing a closure or global channel from parent to child is not modular. It ties the parent to the child.
Observe function composition, lets say I want to build a function that adds 3 to a number and then adds 2 to a number. I have a base function called f defined as:
f(n) = n + 1
now I create two functions through composition:
g(n) = f . f . f
h(n) = f . f
by composing f 3 times then 2 times I have thus created the equivalent:
g(n) = f(f(f(n))) = n + 3
h(n) = f(f(n)) = n + 2
the final function d(n):
d(n) = g . h = g(h(n)) = n + 3 + 2
Every aspect of my created function is modular and I have maximized code reuse. Vue or React components do not have this property. If I build a UI from vue components, the majority of those components can never be reused while on the other hand my d(n) function is the reuse of a single function composed 5 times. The main reason is because data from the child must be sent back to the parent this either makes the child tied to the parent or the parent tied to the child.
The property of composition is achievable with a single source of truth cascading data down to stateless components that only display the data. Modularity breaks on the feedback loop. Is there a category we can invent that will fit the UI mold?
You can also implement v-model, but I don't think that's what you're looking for.