4 ms·
Why not take your comment a step further? That is, you can get pretty far using plain js `createElement` and similar functions. In fact I've created a fairly co
by chatmasta 10y ago
Why not take your comment a step further? That is, you can get pretty far using plain js `createElement` and similar functions. In fact I've created a fairly complex SPA without using any external libraries. Don't use react until you absolutely need it!
Back in the day, jQuery was amazing because it made selecting and manipulating DOM elements easy. But now, plain JS has mostly caught up to that functionality, to the point that it rarely makes sense to use jQuery over plain JS. I wonder if in a few years the same will be true of much of the functionality in react.
- davelnewton 10y agoNo, because "plain JS" isn't a UI framework. We're moving closer to having real GUIs in the browser (e.g., Java Swing) but that's not a function of the language, but the plumbing around the language. Swing isn't Java, Swing is written in Java.
- chatmasta 10y agoIf you use createElement, appendChild, and innerHTML, you can replicate a lot of the functionality of react. In fact react probably uses a lot of that under the hood. Of course for more complex applications, react is cleaner. But for relatively simple components, manually manipulating the DOM like this might be worth skipping the overhead of react.
- davelnewton 10y agoYep, agree entirely, although I wouldn't advocate mixing the two in a single application--mixing mechanisms is added cognitive overhead. But again, JS is just a language, that happens to have an interface into a DOM (in some environments). It's not a framework that guides you in how to organize and architect an app. It's possible to write maintainable, high-performance, complex apps using plain JS. Adding a few simple layers makes it a lot easier, though, and I'd argue that the current crop of client-side frameworks make it easier still. Simple apps == simple code. Complex apps == complex code, regardless of the tools used to create it. Underneath everything, after all, is still just plain JS.
- chatmasta 10y agoWell then to return to your original point that redux/webpage/flux/blahblah are overkill and you shouldn't use them until you need them, you can make the same argument. They are more layers that guide you in "how to organize and architect an app." The tradeoff is that you get simpler code in exchange for more architectural overhead and a more complex build process.
- davelnewton 10y agoI never said they were overkill (and I'd argue Redux or similar pattern is useful even for fairly simple apps). For an app of any reasonable complexity you'll have "architectural overhead" whether or not you're using your architecture or someone else's. That's just a given. (And if you don't, you have more overhead trying to figure out what you were doing.) More complex build process? Yep, if you're not writing all the code yourself, and you want to distribute a single file, and ES2015 (or other) transpilation, and minification, sure. But you can use all the libraries in question without much of a build process at all, just load 'em all up and use ES5. Complex build processes are a result of wanting to distribute and write code in a certain way. They're not a requirement.
- pests 10y agoThis was one of the _problems_ React solves. Before with libraries like jQuery every potential action had to perform it's own UI modifications. As the projects grows you have the same UI element being controlled from many different sections of code. States and state transitions not clearly defined. With React you set the state and the UI will always match, no matter how the current state was achieved. The purpose was to get rid of ad-hoc DOM manipulations. The Flux architecture just takes this a bit further by formally defining who holds onto the state/how it's accessed (stores) and the availible possible state changes (actions).
- davelnewton 10y agoWilly-nilly DOM and state modification wasn't a requirement with jQuery, it was just how a lot of people chose to (not) structure their applications.
- pests 10y agoIt wasn't a requirement but it was encouraged. jQuery was all about selecting a node or node list and then applying manipulations to it.
- davelnewton 10y agoTo "encourage" means to openly advocate. Never ever have I seen active encouragement of poor programming discipline. You are correct in that's what jQuery was about, but it had no opinion on how to go about that task.
- pests 10y agoIt might not have a explicit opinion stated anywhere but in any library or framework, the API provided influences how those APIs are used. By having the central unit of work start with a query selector is one such influence which I feel implicitly encouraged DOM manipulations. Taking a look at the original jQuery website on web.archive, this is the introduction to the $() function: "The functionality of jQuery centers around one central function: $(). Everything in jQuery is based upon this, or uses this in some way. The most basic use of this function is to pass in an expression (usually consisting of CSS or XPath), which then finds all matching elements and remembers them for later use. For example:" And then goes to show a DOM selection followed by a chained mutation.