3 ms·
How many people who are critical of the current state of JS actually use it on a daily basis? Modern frameworks like React and Vue don't exist to fill in the ga
by mmcnl 4y ago
How many people who are critical of the current state of JS actually use it on a daily basis? Modern frameworks like React and Vue don't exist to fill in the gap left by native JS, they exist so that you write your application in a declarative way where the view is rendered as a function of state. This relieves the developer of keeping track of DOM state, as you only declare the render function once, and after that you only need to manage state.
If anything, modern frameworks tend to build as much upon the native functionality that is available. This reduces bundle sizes and increases performance. It's an abstraction on top of the browser capabilities, not a clone.
Now, onto the code itself. The author claims it is "pretty simple" to build "fairly complex things". He backs up the claim by stating it took only 60 minutes to write this app.
First, I would be careful to claim things are easy or difficult. This is very subjective, and phrased in the wrong way it can also come across as arrogant.
Second, the app is not simple. Looking at the code the author created his own DOM abstraction. The current abstraction is only proven to work for a simple to do app.
Third, a to do app is not a "complex thing". Not even remotely.
It's a nice exercise, but the conclusion drawn by the author aren't valid.
- klabb3 4y ago> React and Vue [...] exist so that you write your application in a declarative way where the view is rendered as a function of state Exactly. To elaborate, here's the big, big caveat in a miniature form: https://github.com/1Marc/todomvc-vanillajs-2022/blob/854dd40bdf0facfdcdbd116b6c37dee906168254/js/app.js#L82 https://github.com/1Marc/todomvc-vanillajs-2022/blob/854dd40... Note that this clears and recreates the DOM on every action (eg mark complete), and DOM ops are the most expensive ones. This is a sound strategy for vanilla JS, because the alternative is mutating the DOM and keeping it in sync which is error prone to put it mildly. I use frameworks very sparingly, and am always cautious with deps. But a reactive UI/diff engine is non-negotiable for me.
- dimgl 4y agoYep, you nailed it. I've been looking at low-JS and vanilla JS again recently given the amount of hype around these kinds of frameworks (and the perceived maturity of the browser). It still has the same problems you describe. You worded it way more eloquently than I can.
- wruza 4y agoThis relieves the developer of keeping track of DOM state, as you only declare the render function once A good part. and after that you only need to manage state A part where to change a[n].b.c: React: you either split into unhealthy number of “components”, which are never reused and require tons of pass-through, or only manage state as a sequence of unnatural to js “reduce” operations. Vue: give away your data to Vue, because once it hits `.data` it gets charged with properties incompatible with the entirety of js language. Vue is essentially a separate programming language, which somehow managed to sell the manual transpilation to its users. React did the same being Haskell-like variant. The “upon native functionality” of this is equivalent to python3.dll being upon a native functionality of C++. Most of your points still valid, I only wanted to unfold that “only manage state” bit. It’s sad that libraries like Mithril aren’t the default, and instead monstrosities like React are.
- mmcnl 4y agoYou have to manage state within the rules of the framework, that's true. But the hard part of programming usually isn't syntax. Who cares if it's a different language/paradigm? It's a simple language and I only have to say a few words. It's still orders of magnitude less complex (this is not an exaggeration) than rolling your own framework with vanilla JS. I would encourage you to find out why React is popular and why Mithril isn't on the assumption that the world isn't crazy.
- wruza 4y agoAre you familiar with both? Finding out why React is popular is a hard task because every article starts with comparing it to jQuery and usually ends there. I’d like to learn from the relevant side, not from the one centered around some obvious strawman. A link or just few words, I would really appreciate it.