News for hackers. Stuff that matters.
Re:How to manage HTML DOM with vanilla JavaScript only? by greggman3 on Thursday April 02, 2020 @03:42PM (#22762865)
It's 10x the code now. 10x = 10x more space for bugs and bad design.

Use to be I might setup a handler on an input element to update a value. Now I have to write an action factory to generate an action to get reduced into a function that updates the value. From simple data.prop = elem.value to 4+ functions and a bunch deep deep overhead.

Now I'm not saying all that structure doesn't have benefits but it's also a large amount of rope in which to hang yourself.

Re:How to manage HTML DOM with vanilla JavaScript only? by nicoburns on Thursday April 02, 2020 @03:55PM (#22763023)
I honestly think it's about a quarter of the code. Yes, there's a bit of ceremony around state management (but you are also free not to use Redux). But it's mostly boilerplate with a prescribed structure, so IMO it's pretty difficult to get it wrong.

On the other hand, most of the code has always been DOM manipulation, and having that declarative rather than imperative is a huge win. The alternative used to be using a template engine like handlebars, but that did a complete re-render every time any state changed, so for anything moderately complex that was too slow and you had to fallback to manual DOM manipulation, and manually keeping the DOM in sync with your state. And that was a large amount of rope in which to hang yourself

Re:How to manage HTML DOM with vanilla JavaScript only? by mosdl on Thursday April 02, 2020 @06:03PM (#22764376)
Yet we all managed to write complex web applications without much trouble that performed better than React ever can. DOM manipulation was needed rarely actually - usually you replace subtrees anyways (switch tabs, etc).
Re:How to manage HTML DOM with vanilla JavaScript only? by Drew_ on Friday April 03, 2020 @05:07PM (#22773962)
If DOM manipulation is rarely needed then your web app isn't complex, it's at most a collection of CRUD pages. UI Frameworks like React are for building UI's that accomplish a lot more than that through frequent DOM manipulation. If all you need is CRUD then templating frameworks still exist, are well maintained, and widely in use.
Re:How to manage HTML DOM with vanilla JavaScript only? by mosdl on Friday April 03, 2020 @08:22PM (#22775148)
Even in complex apps, most of the DOM remains the same and you are changing several properties (some text, changing some classes).
Re:How to manage HTML DOM with vanilla JavaScript only? by spiralx on Monday April 06, 2020 @07:39AM (#22792801)
That's not true as soon as your UI contains conditional logic or a list of elements, at least one of which will be present in almost every web application.
Re:How to manage HTML DOM with vanilla JavaScript only? by orange8 on Thursday April 02, 2020 @07:34PM (#22764977)
> ... and having that declarative rather than imperative is a huge win. The alternative used to be using a template engine like handlebars

While React markets itself as a declarative DOM manipulation library, any kind of HTML templating system is declarative out of necessity. Why? Because they all produce HTML in the end, which is itself a declarative markup language.