r/javascript • • Jun 28 '18

The exact same app - 1 version made with React, Redux, and React-Router The other made with Vue, Vuex, Vue-Router. Good if you want to see both worlds. User Auth with JWT, note CRUD actions, Koa (Node) backend. MIT license.

https://johndatserakis.github.io/koa-react-notes-web/
459 Upvotes

98 comments sorted by

View all comments

Show parent comments

2

u/jkoudys Jun 29 '18

Does "less code" really imply a "simpler coding experience", though? As a 3rd-party reading your code, I look at something simple like your App.vue, and look at how many modules are implied to have loaded without actually specifying its source. The <footer-main> for example, requires that your router.js is loaded, which registers a Vue.component (essentially a global) so footer-main is your Footer.vue. Not only is it harder to reason about, but it limits us if we want to code-split the chunk too.

If you're using direct imports, every missing one shows up as a big squiggly red line from static-analysis in my editor long before runtime. Every non-trivially small component can be included via an import(), so it only gets its chunk loaded when I decide it's needed.

There's a lot more that forgoing pure ecma for a micro language hinders you for too. Dead-code elimination is basically impossible, both because Vue.component and router are essentially globals, and because so much of the control logic (e.g. v-if) is in microlanguage. There's the complexity of needing to learn, write, and reason in multiple languages at once (both harder to build and reason about -- with React and emotion, I don't need a single line of CSS, or to write any HTML beyond the tiny boilerplate react-create-app makes).

Don't think I'm being too critical - super happy you wrote this and released it to everyone. I do think a lot of your problems with react are based more in familiarity with vue, and React not being enough like vue isn't really a flaw. Some of your criticisms of individual libs (especially router) are pretty spot on, but you're also not following some basic patterns that React devs (especially the FP-loving ones) routinely use. e.g. out of array methods map, reduce, filter, find, Array.from, [... ], etc., I find only a single Array#map, which is pretty unusual for a React app. React's all about passing in the same collection as a prop to different components, and rendering them differently, e.g. a collection of restaurants could be mapped to a bunch of pins on a <GoogleMap> in one place, a text list in your <Itinerary> somewhere else, Vegan options: {restaurants.filter(({ cuisine }) => cuisine === vegan).length} in another component, etc.

2

u/adstwlearn Jun 29 '18

Upvoted. I don't think you're being too critical. It's just one of those things where this is a full example, so there's a lot of moving parts. I would argue that things like <footer-main> all follow the same exact pattern, so while it may seem strange at first, you'll pick up the structure right away.

Regardless - there's definitely something to be said about how you have to explicitly do certain things in React - like adding routing support to the footer if you wanted to push from there. I can definitely see the argument that it keeps things more focused and compartmentalized.