I haven't gone through this page yet, but thank you for at least the attempt at reaching somebody in my state of affairs. Front End work is very hard. The front end design & what I would call the back-end front-end disciplines are supposed to meld together according to job postings and over-zealous recruiters, but it's a good deal more complex than I have been willing to put up with, mostly because of the materials to get started and the unintuitive tools that people who know what they are doing swear by.
Imagine being solid at design, pushing pixels, using HTML, CSS. Then suddenly these program frameworks which are created by back-end programmers not visual designers appear and the ramp up for the average technical person is immense. For me it's been enough to turn me off them all together and make it a talking point that "my javascript skills fall off at X,Y or Z" so recruiters and employers know that despite being able to do a lot, I can't suddenly become everything UI and everything back end just because the title of anything "front end" is so versatile.
<ul ng-repeat="item in items">
<li>{{ item }}</li>
</ul>
The Angular template is more readable at the expense of ngRepeat's complexity. Neither example includes Component/directive boilerplate. The directive boilerplate is generally worse, because it requires a separate template file or an ugly template string, knowledge of the directives API itself which is baroque in the extreme, and $scope-wrestling (whereas JSX' scope is the same as JS').
In my opinion reuse of the React component is more straightforward, you explicitly import/require it while in Angular you specify its providing module as an angular.module dependency, which has implications for config block ordering.
I used to struggle to answer this when talking to Angular folks about React. Then I came across a situation where I needed to recursively build a DOM tree based on complicated calculations on a per-node basis and also calculated values at the top level. If I'd been doing it with ng-repeat, the logic would be split confusingly (and unnecessarily) between the template and the controller, and I'd need to pass down any information from the top-level ancestor manually.
In React, I just create a renderNode method that's called by render at the top level, and renderNode on non-terminal nodes returns <div>{children}</div> where children is a map whose mapping function returns this.renderNode. The entire algorithm is grokkable at a single glance, and there's no need to create Directives to add any fancy features or special cases in the future. No need to read pages of documentation about ng-repeat and its intricacies; it's all just Javascript.
Yes, Angular "just works." But React "just works" the first time you try it.
This obscures React's main strength, which is making it so that you don't have to worry about edge case states. In complex UI's, this is the #1 source of bugs.
For sure! But you should have empathy for the front-end designer who may not totally understand the advantages of React over "traditional" HTML templates and directives.
If you like Angular's style you can use react-templates [1], most people just prefer the React way. In theory there shouldn't be any overhead, but since in JavaScript abstractions aren't free you're going to pay some price.
Also the angular equivalent would be
<ul><li ng-repeat="item in items">{{item}}</li></ul>
And the react-templates equivalent would be
<ul><li rt-repeat="item in this.state.items">{item}</li></ul>
It would be some array defined on the angular $scope object, presumably instantiated when an angular directive/controller is instantiated for a component. I'm guessing that's roughly analogous to "this.props" in the react example, though I'm not very familiar with react.
I feel your pain. Job expectations for front-end work (and, no doubt, other tech areas) have grown terribly incoherent. It seems like a lot of companies expect new hires to train themselves into unicorns on their current employer's time, when they could just hire someone now and give them a decent amount of time to ramp up instead.
I think for the needs of front end, the recruiting world would be better off targeting back end people heavy programmers, maybe .net or java and their migration to the front end frameworks will be much easier than the designers will be. It sounds awesome for a designer to pick up javascript and just run with it, but I personally see a pretty thick wall between focusing on design, graphics, presentation and then solving all the programming problems to go with it. Again personal experience, it's been easier for me to shut off the valve of code completely, so I'm not distracted by consequences of how it will be built. I know that sounds counter intuitive but just knowing some of the avid javascripters, those who can build apps with it, they don't really have the ability to get out of that mode to design something, they are always living the framework. They will make something nice, but alone their work rarely surpasses the level of beauty or refinement of a really good designer artist.
Yes I know those hybrids exist, but unfortunately there aren't nearly enough of them to fill all the positions. Not only that, but I'd argue that a lot of them who are hybrids, you're not going to get their best work from both areas if they are expected to deliver from both disciplines on projects. Not on the deadlines that employers will set at least.
And I suspect a similar problem exists in actual building architecture. Yeah some building designers are good at accomodating for all the variables of planning codes, but they aren't going to be (nearly as often) fantastic at aesthetics that somebody who works outside those constraints might be capable of. There's a lot of value in designing first, then put those styles of thinking together (designers and architects) separate people and from that point later in the process of creation you start solving the challenges like plumbing codes, metallurgy afterwards. Part of this is me complaining, but it's my attempt at experience of always being a crossover person and how you never really feel like you're honing a craft, you just feel like you're being left behind and not properly cultivating what you enjoy most.
The problem is anyone who identifies himself or herself as a backend person probably hates dealing with HTML & CSS. And that's without also getting into the backend devs who also despise Javascript. As far as I can tell anyone who is a backend dev only is saying "I don't want to deal with any of the bullshit on the front end." Good luck convincing those people the next technology they should learn is React or Angular or SCSS.
These frameworks are not actually created by back-end programmers, clientside code has become as complex and specialized (sometimes more) than the server in the past decade.
But there is still room for good designers who code; plenty of research, user testing and prototyping to be done before getting down the tech rabbit hole. A good team is multi-disciplinary and not necessarily composed of 'unicorns' only.
Speaking as someone not intimately involved in the web development community, React looks decent but absolutely not worthy of the obscene amounts of hype it received... unless what web devs had before was really that horrible, because that's the impression I got. Though from what I can tell, jQuery and React are somewhat orthogonal tools, as I have used the former and it goes beyond rendering views.
What I cannot figure out is all the harping on about "functional style". The React examples all felt more Smalltalk-ish to me than anything else (I suppose unsurprising given JavaScript's vague influences from Self). The use of closures doesn't really change the conceptual patterns much. Is it because the tutorial can only cover so much ground, or is it that since some of the primary buzz around FP was the management of mutable state, to the point that people now instinctively associate the idea with FP?
> unless what web devs had before was really that horrible
As a big fan of react, I think that this isn't really a fair thing to say. I feel as though this statement implies that front end dev is not complex and therefore it surprises you that there is room for significant improvement. I'm sure that's not what you were thinking, but really, building complex imperative UIs with state can be very difficult, and react does represent a new step in the paradigm shift away from imperative development. Whether React is the future or not, components and composition are here to stay, and I think a increasingly large portion of the community is interested in writing web applications with immutability--all of which suites flux (and react) very well, and does not suite jquery very well.
React doesn't enable anything that you simply couldn't do with jquery and backbone, but it does make a lot of it way easier and reduces overall complexity by a ton, especially if you're developing with component structure and immutability in mind.
Before React: to make a transition, let's change this, this and then that, mutating state on every step.
After React: have one pure function, which takes as input the current state and produces the desired output.
This is the main shift. It's very similar to how imperative programming is done in Java vs Haskell.
Are they pure? I don't think JS has any way to guarantee referential transparency, though of course the use of a virtual DOM can mitigate side effects by having well-defined behavior.
Furthermore, the input-process-output model can hardly warrant being called "functional" in of itself, unless you really want to overload the term.
The React way of independent handlers that trigger events which incrementally calculate state and update views, is, in fact, quite similar to how Smalltalk UI paradigms work, right down to the installation of an event handler resembling a message send operation.
If they are not pure, you are literally making an error (as the framework states they are supposed to be pure).
input-process-output is how pure functional languages (such as Haskell) deal with imperative coding. You push the imperative part to the top of the call stack and try to keep the rest of the computation pure.
JavaScript inherited quite a bit from Smalltalk, so you will find similarities like these in JS in general.
Flux supplements the standard React bubbling of events up the chain of components with a simpler, singular flow, making it even more functional.
That sounds like a try-hard simplification. Input-process-output is pretty much a generic metaphor for programming in general. I don't think React has anything like monadic encapsulation (not that a language like JS can conveniently accommodate it). You're observing a few high-level properties of a given paradigm and extrapolating an inferred architecture solely from those points.
In fact, you're equivocating the entire management and abstraction of mutable state as an inherently "functional" thing, which it is not. OO is just as much capable of factoring state as a virtual resource that you explicitly make transitions to and from and transparently or visibly share increments across object boundaries, as this is exactly what e.g. Self does with Morphic, right down to the same event handler structure. Just because one is a lambda and the other is called a method doesn't make a huge difference.
I'm saying that just about all of React's insights were done previously almost verbatim in thoroughly object-oriented environments. That some FP evangelists have a kneejerk hatred for it doesn't mean the mental gymnastics for insisting one over the other is necessary. They can be complementary.
But I haven't written that input-process-output equals functional. I just pointed out that the React model allows for a larger piece of the code to be functional, in exactly the same way it's done, say, in Haskell. This has nothing to do with monads. Monads are used for the imperative, stateful code that is pushed to the top of the call stack, the bit which is partially managed by React for you (by calling the render method).
I would also never claim that React invented any of this. It just popularized this more declarative approach for building Web UIs
I thought your analogy was spot on. In React, the view is reduced down to a functional projection of the model - rather than being a complicated set of state interaction patterns (eg. mvc,mvvm). The React framework then handles the real DOM update - in the same way that a Monadic IO computation is not executed directly - but instead is passed to the Haskell IO runtime to be executed.
I haven't used Morphic in years (and I used it in Squeak). While you're right that Morphic shares some things in common with React, the fundamental difference is that when a composite morph receives an event and needs to change, it has to explicitly pass messages to all of its submorphs to transition them to the next state. With React you simply throw out the old subtree and replace it with a new one. This is similar to how drawOn: works, except that throwing out and re-instantiating your submorphs for every drawOn: is expensive and loses UI state. React gives you this abstraction.
Additionally I'm not sure where you're getting this "JS can't be functional" opinion from. Just because it doesn't give you compile-time or runtime guarantees, or because the syntax may be more clunky, doesn't mean you can't get these benefits by convention.
Additionally I'm not sure where you're getting this "JS can't be functional" opinion from.
I never said this. I was talking more about the React architecture, specifically.
Though in general there is this phenomenon to grasp at any similarities and start espousing how functional a particular language/framework/library is, as if for street cred.
Before React: to make a transition, let's change this, this and then that, mutating state on every step
That's nonsense. There have been data binding frameworks used for well over a decade in JS development - I know I wrote one in the early 2000s. You can't write a decently sized app in JS without developing something like data binding, unless you love busywork and bugs, or have zero prior experience of what came before in GUI frameworks.
Data binding is designed exactly to prevent the need to explicitly mutate all the views at every point that the model can change. Instead you write bindings that project the model into the view, and make the model reactive, so that changes to it propagate automatically. It's the same in any decently sized Backbone app - that's why the Collection and Model give you all these events.
What's new in React is the idea of cheaply creating a virtual DOM and extracting a set of diffs from it that can then be applied to the real DOM. I did something vaguely similar, again in the early 2000s, but the motive then was to reduce the amount of data on the wire (the server had a data-bound model of what was displayed on screen, but only sent diffs back to the client). It's a neat idea and an excellent implementation, but it's not original or groundbreaking.
It's just nicer to use if you have complex UI. OP's response was poor IMO, just because something follows some abstract principles doesn't necessarily give it value for us. I'll give you examples of things I've worked on where React made sense & where it didn't:
-E.g. use React (or Backbone, Angular, etc.): A real-time document editor, with many interacting components, with lots of real time updating of the UI. Definitely needed a framework like that, and it was great.
-E.g. don't use React, because in these cases it's a total Rube Goldberg machine (extra steps to achieve the exact same outcome): Basic web app with some ajax submissions, adding results to DOM type of stuff. Maybe small html fragments cloned, inserted by jQuery. No extra fancy client interactivity.
^If people claim you should use React for the latter (undoubtedly some will), they are very likely just people who follow trends to follow trends, or maybe don't have a ton of web experience and it's one of the few things they've learned and are sticking to. It's just so unnecessary (not to mention 100kb+ of overhead, & in my experience comes out to about x3 the amount of code). But yeah, absolutely use React if it's anything like the first use case.
1) React does not make simple apps overly complex. It might feel like more work if you are more used to jQuery. If you are used to React instead, it really won't have a huge negative impact on a small app.
2) React will scale. It will be a much better vehicle for future development (as you admit, it is more suited for more complex cases than jQuery).
I was not making a judgement on the value of the approach, although I personally believe that this paradigm shift has a huge positive impact and is applicable in lots of cases. If I can choose between lots of computation intertwined with state mutation and a declarative approach where the mutation happens on the smallest scale, up the call stack, I will always choose the latter (of course, unless you have to mutate to gain performance).
I didn't say it's more complex, I just said more steps.
Yes, if app is planning on being more complex, sure use Angular or Backbone or Ember or React. Otherwise, don't. Your pet projects sure, use it; if my team is billing clients, I've learned from experience, you're screwing them if you're not just using basic jQuery or even raw JavaScript which is a lot better to work with these days. If your reasons are only rooted in your abstract preference of design ideals w/o looking pragmatically at the situations, you're likely doubly screwing them.
Fyi this "paradigm shift" is like 8 years old, React is not disruptive, it's just another variation.
Pre-React, you would often duplicate every bit of logic. You end up with "here's what you do on first render" and then for each mutable bit you have "here's how you change the DOM to get it back to the right state". With React, you only write the first one, and just re-render all the time. The interesting part of React is how it keeps that performant.
This is a more general declarative vs imperative question so if you search for "declarative programming", you should find lots of examples. But here is one, taken from Bret Victor[0]:
Now, imagine we first wrote the code for stem and leaves, than later added the code for the flower (in the reference, copied it from elsewhere). The code has a bug in it - the leaves are red. This is just one example: once you have a "hidden" state, you have to manage it. You always have to be aware of the effects that every line makes on the state and how the state affects the other lines. A "React"-like (simply declarative) API would look more like:
The code is now referentially transparent, I could replace uses of variables by their values and nothing would change, since the functions have no effects. The effects are pushed to the edge of the code, in this case the call to draw which actually performs the drawing, or when React updates the DOM with the results obtained from a render method.
Have you done Backbone? The idea is that you define everything in terms of models and that when one of those models change you call render() to run it through your templates and you're done. This is a simple conceptual model, the framework needed to execute it is simple (and well written in the case of Backbone), and it works really well for simple applications. The problem arises when you can't just call render: when you have input fields, when your rendered DOM has event listeners, when you're using a component with it's own internal state (e.g. a jQuery datepicker), or when you're doing something like a grid and generating too many DOM nodes. Unless you know this is coming and have a plan for dealing with it (e.g. the many Backbone addons), this is a complexity land mine since it does not show up in the small apps you build while testing out the framework.
You can (and I do) view the React render as an idempotent projection from state to DOM, otherwise known as a template. React is a very fancy template system. You build your fragments (components) up into views, pass in your data, and render the entire page as if you're rendering it from scratch. It handles or provides hooks for all the situations I mentioned in the previous paragraph and React's internals ensure that it's reasonably performant by default. Having everything conceptually fully render from scratch every change means there's no separate handling for the initial render versus updates to the initial render (e.g. you have an accordion, render it with an ejs template but toggle it open/close by toggling classes). It makes the Backbone model work in a way that's easy to reason about.
A real world example: I've implemented (B2B, not something I can link) a drag and drop layout builder as a contract. The workalike they wanted, which I had also worked on but didn't design, was ~6k lines of node/class manipulation and mousenter/leave hit testing while my React version worked out to be around 600 lines, most of which were generating virtual screen position hitboxes for the various drop zones. Hovering/dropping in a zone changes attributes in a list of JS objects and the visual feedback is handled by the rendering code you'd need to draw the layout anyway plus another 20% for the drop previewing/hovering.
Most savings aren't as dramatic but in general you wind up spending less effort getting your views right. The LoC isn't always that much lower but it's template code instead of manipulation code. There are other benefits like component composition just working, server side rendering, putting all your app state in one place lets you do session recording and time travelling debugging but this post is long enough as is.
I think that the reverence of current frameworks is a response to the faults of the previous framework that was revered.
We started with JQuery. It was fast and had a simple API. People started to learn JQuery more than they learned Javascript. You even had Stack Overflow answers that nudged people away from Javascript stating the robustness of JQuery's libraries (specifically how it worked the same on every browser).
Then, we realized that we did not want to set up our events as one offs. The result was very spaghetti code. Backbone came out of this. It was light and allowed us to modularize our code. However, it didn't really give enough structure so we switched to Angular. Angular was the holy grail. It did everything for us. Events automatically propagated state changes to our objects and automatically redrew our view afterwards. We didn't have to think anymore. It did the thinking for us.
Little by little, we started to realize that when you outsource your thinking to your framework, you end up getting stuck in crevices that your framework hasn't anticipated. In Angular, it's difficult to share state between controllers. It's outstandingly slow in that it redraws far too often. The thing that I personally was most sore about was the fact that Angular, similarly to JQuery became the new Javascript. Instead of learning how Javascript works, you needed to learn how to use Angular. This means that you couldn't just port in good Javascript code directly. You needed an Angular directive. Try using a simple charting library such as HighCharts. The examples don't work as is. You need to use the Angular version. It gets messy and all that modularization starts to work against you. It works against you because you don't have control over your javascript.
Here comes React. It takes a step back from the hand holding of Angular and just handles the rendering. You can design your Javascript classes and functions as you see fit. If you need to port in Highcharts, go for it. You can use the JQuery plugin if it suits you. All React really does is handle the rendering and re-rendering of your dynamic content on screen. It will also allow you to propagate events that will change the state of your objects, but does not do so in the same way Angular did. It gives you more granular control.
I suggest you try it out. The JSX syntax might throw you off at first, but don't give up. It's necessary for how React obtains its amazing speed. If you're just getting started, don't worry about the difference between Shadow and Virtual DOM.
It absolutely is not difficult to share state across Angular controllers. Services work great for this. I also dispute that you are too far removed from "vanilla" Javascript when using Angular. I recently integrated some externally written d3 javascript code and it works as expected without forcing a conversion to "the Angular way". Finally, I certainly dispute that Angular is too slow. Our Investmynd app has a fairly data and interaction heavy front end, and its performance is quite snappy if I do say so myself. :)
Now what I do think is true is that Angular is a fairly complicated beast, which when combined with the poor standard documentation, makes it a non-trivial endeavor to learn and use properly.
I'm happy that it works for you. I'm just sharing my opinion of the framework so please continue to use whatever makes you happy.
As far as using services to communicate, I personally believe that its simpler to emit events. My absolute favorite way is how Mithril makes properties accessible anywhere. That way, you can just pass references around. It's not so important how you communicate, but the complexity of doing so. I believe that in your last sentence, you might have described the point better than I. It's a complicated beast. For that reason, you have to work within its domain. You can't invent your own way of doing things. You can't apply your trade in the way you want to. I suggest you play around with a React app and pay attention to the best practices of organizing your own javascript code more than what React itself does. It's refreshing.
I do plan to continue to use what works for me. I also plan to experiment with React. I'm just pushing back a bit on the suggestion that Angular is not a viable framework in its own right.
Regarding services vs. events, I guess that's down to personal preference. I find a singleton service holding shared state much easier to reason about and maintain than I do events (for certain things, like shared client side session state...I certainly do use events when appropriate).
Regarding "doing things your own way", I guess that's a personal preference as well. Personally I like to nail down a few common implementation patterns that get the job done and then repeatedly use those and save my focus for the business problem at hand. I'm fine with the framework strongly suggesting or even requiring those implementation patterns as long as they work and aren't overly cumbersome.
> It absolutely is not difficult to share state across Angular controllers. Services work great for this.
From what I saw in the last Angular app I worked on, the ideas that services can work for this and that things can get difficult fast when sharing state across controllers aren't at odds.
Hmm, shared state in and of itself can certainly cause difficulties (hence the recent focus on immutability and FRP), so I agree with what you are saying. However, if you are going to have shared state, I find the Angular service singleton approach as good a way to handle it as any.
It's considered "functional style" because react is a functional reactive programming framework.
This is about more than just managing state.
If you're not familiar with FRP, then I think learning more about the theoretical side might help clarify why everyone is describing react as functional.
I have never seen React described as FRP, and a Google search for "React FRP" confirms that this is a heterodox belief and in fact it is you who might need to learn more.
I was thinking about react + flux, eg this line from the flux overview [https://facebook.github.io/flux/docs/overview.html]: "This structure allows us to reason easily about our application in a way that is reminiscent of functional reactive programming, or more specifically data-flow programming or flow-based programming, where data flows through the application in a single direction — there are no two-way bindings"
Anyway, I imagine people refer to react as "functional" because they conflate "declarative programming" with "functional programming."
Shameless plug: I wrote my own React introduction—geared more for people that know some JS and HTML, but not necessarily any other JS libraries. More specifically, it very gradually builds up from rendering a single JSX tag to enough components, state, and props to build React's to-do example. I found React has an unusually gradual learning curve—you can really build up concepts bit-by-bit.
As someone who knows Angular and Knockout. I found this great. Because react is a different way of thinking IMO that most tutorials I read were not easy to get up and running so I just threw in the towel and forgot about react. Most people make too many assumptions on the skill level of the reader (myself included when I blog) and it can be frustrating.
Knockout.js is my favorite because it doesn't make me hack my HTML documents into pieces if I don't want to, but if I want to, it lets me make web components that work all the way back to IE6.
I also like that it doesn't require anything beyond normal HTML to make templates and it doesn't require learning some huge framework just to bind a simple data-set into the page. You can also read through the entire code-base in an afternoon.
I worked on a project with around 20 developers using knockout (with two lead developers essentially writing their own framework as we went) and it was a ridiculous mess. I think it can be a good tool for prototyping, but it is horrible on a large app. You're always changing some observable and having something far far away break completely. React with immutable.js is much better because you really can focus on one component at a time in complete isolation.
Maybe slightly off-topic, but the tutorial page adds entries to my (Firefox) back button as I scroll down. So when I tried to "back" to HN, nothing happened. Second, third back, nothing happened. Opening the back list, a dozen or so entries and they all do nothing.
I think this kind of design should really be avoided, it breaks my user experience.
Yeah, I'm really getting tired of this "You just changed pages and didn't know it" pattern I'm seeing more and more. I'm not sure why people want to have this single page app at all costs, but if you want the single page app, than a single click of "back" should work.
I think there is value in doing single page apps but mostly for web applications not really for just a website. Still I completely agree that breaking the back button needs to be avoided.
I think a more useful distinction is - mess with back-button history if and only if the user perceives a page transition regardless of if the location bar changed it there was a page load.
Consumable content aside, I absolutely love the format of the tutorial. It's significantly more pleasant to dig into compared to what seems to be the more common tutorial format (e.g. [1]).
Is React meant to replace Ember/Angular type of frameworks? Can React also connect with backend APIs to fetch JSON and present them on the frontend? I've been waiting to nosedive into Angular2 (when its out), is React a better alternative to get started with?
> ? Can React also connect with backend APIs to fetch JSON and present them on the front-end?
Technically? No.
React doesn't include the direct code to main API calls. You're still going to need to make the 'API calls' 'yourself', whether with jQuery or raw XMLHttpRequest or whatever. React comes into play when you have the data and you're ready do actually do something with it.
Yes, it's pretty much unnecessary to include React and a framework like Angular, Ember, or Knockout in the same project. And of course React works well with REST and GraphQL APIs for communicating with a backend. React is definitely a better alternative to a heavyweight framework like Angular for new projects.
As a relative newcomer jo JS frontend development, is there a canonical JS REST client library that works well with React / Flux, or do I have to write that myself?
Thanks, appreciate the pointer - the idea of adopting something potentially a future standard through a polyfill is appealing. @pvg I take your point about lack of browser support, but that's what polyfills are for after all! :)
In the meantime since asking I also came across restful.js (github [1], blog [2]) - it's new, but looks like a good framework-neutral alternative, if a little heavy at 27K minimised/uncompressed.
Edit: Actually, fetch.js + es6-promise-min.js = 26K, so not much in it.
Fetch looks interesting but as far as I can tell, it's an in-progress standard with no support on any version of Safari or IE or any mobile browser whatsoever. Seems like it has a bit to go before it being 'native in modern browsers'
You can polyfill it in those browsers. Just use polyfill.io, or if you prefer, manually feature-detect it and if necessary load Github's fetch polyfill, which is good: https://github.com/github/fetch
React certainly replaces Angular as a View+Controller framework (idk about Ember, although I know there's been work on integrating the performance benefits of Virtual DOM).
In scenarios with complex interactions, something like Flux is desirable, however small web apps work fine with simple JSON REST APIs.
React will probably just integrate those as they become usable, since React acts as a layer of abstraction between the DOM and your presentation logic.
Not so. React does not really play well with web components. Currently React has to internally define JSX elements for every known HTML element that's out there, namely to track internal state and respond to events (i.e. input fields). Because they won't be able to do the same for the vast ocean of web components that will be authored in the coming years, it will be difficult to provide clean interop with new custom elements. The React maintainers have even stated that they don't believe web components are the right way forward for web application development. React was never designed to work well with web components in the first place. On the other hand, the main reason why Angular 2.0 is such a drastic rewrite is because they needed to do it in order for Angular to work seamlessly with Web Components. It's no coincidence that both Angular and web components are Google initiatives.
You're wrong about web components and react. As of 0.12, if you register a web component like you normally would, you can reference it in a react component. React no longer has a white list, and instead assumes all lower case tags are HTML tags (standard or custom).
The only drawback is that it doesn't support custom events out of the box. Instead, you have to manually create event listeners on elements on mount. As far as I can tell, there's no reason why it couldn't in the future though; Web component adoption is so low right now that it just hasn't been something people have complained about.
Not supporting custom events is pretty much the same as not supporting web components. What if you use a third party web component that has dozens of events? The goal should be interop with no additional plumbing required.
There was a time when React literally just didn't support web components, so I don't think that's really fair. Yes, it would be nice if it worked completely free, but if you're only listening to 2 or 3 events on a component, it is definitely a fair price to pay for being so bleeding edge.
But Angular is a glorified templating engine, where react is really about FRP and rendering from data. The React components you write are essentially web components that use DOM; as long as there are standard building blocks for web components in the future, you could easily port it to React.
Yes, but now you're requiring that developers go through the work of porting every single third party web component they might want to use in their project. That's the current pain we're all going through today with Angular, React, Ember, etc, which are basically glorified web component polyfills when it comes down to it. The whole point of Web Components is portability.
> Can React also connect with backend APIs to fetch JSON and present them on the frontend?
Yes, obviously. My company uses it for this. Personally, I don't know if AngularJS is a better alternative moving forward because it has a bigger community and companies such as Microsoft are integrating it on Visual Studio.
How revolutionary does it end up being if you have to farm out a lot of hte stuff you'll do to other JavaScript libraries which presumably do not have a native component?
I've been told by several friends who love React that this is one of the main selling points.
It basically just gives you a view engine and then you have the flexibility to select what other libraries you want to supplement the rest of the app components.
This differs from other frameworks like Angular where you have to "go all in" and don't have the flexibility so that if something major changes (like when the Angular team announced HUGE changes coming in 2.0) you might get stuck with something you don't like. In this way, it's easier to switch out a part of your app as opposed to having to completely rewrite something if you use a full framework like AngularJS.
I get that but there's a sort of value to a monolith that gives you most of what you'd need to build an SPA with a "guarantee" that all the components are reasonably good too.
I said React Native is revolutionary. It's the first JS framework that lets you build native iOS and Android apps. Key word here being "native".
React itself was designed as a UI library, purely to be used as the "V" in an MVC app. It's like expecting D3.js to do your AJAX calls. Unless it's a full front-end framework, there's no point trying to do everything.
I mean that the competing frameworks are whole application frameworks instead of just a view; being able to write them and compile them to native would be even more powerful.
Sorry but nowadays I feel that jQuery is like php for the frontend: people get results fast but the average code quality is so shitty. Why on earth is jQuery used for things that normal js can do instantly? There are so many libs out there based on jQuery even though this dependency is absolutely unnecessary. I might sound arrogant but people should get an understanding for JavaScript and learn how to use it before stacking layers of abstraction. Ajax with normal JS for example is not so hard. One doesn't need all the fancy angular/jQuery/whatsoever helpers. If one knows the basics it's okay to use some convenience stuff from time to time but I feel that so many low quality devs are solely relying on their precious xxx kb libs just to display a simple hello world.
I have a friend with a web publishing business. She uses guess and check with text edit copy/paste to build websites for clients. I've shown her the console log countless times and she always rolls her eyes when I extoll its value.
She makes 50% more than me, has cash in the bank, and loves her life.
All I have is picking on her javascript. And I'm not even really any good at it.
I think there's no reason to be correct when your goal is to buy food and pay rent.
No offense, but what do you do where a guess-and-check person makes 50% more than you? Is she just hustling for clients who have no idea what they're doing re: web design and using marginal technical knowledge to make pages for them?
I'm totally with you that jQuery is a crutch for a lot of devs, but it's also the easiest way to ensure backwards compatibility for IE 6+. If you have enterprise customers who refuse to upgrade it's probably the most stable way to support them while leveraging the power of modern browsers for enlightened users who have them.
Good that you mention this point. This is for me the main reason to use jQuery in a project: backwards compatibility. I am gladly in the position where I make my own business decisions and so I choose which browsers I want to support. That said I totally refuse to support super-old browsers like IE6. I even refuse to support IE9. If someone has trouble using a site built on modern standards: Go get a modern browser. If it looks shitty on your old IE6 then don't blame me.
I have looked at react.js a couple times after reading more and more buzz about how fantastic it is. However I'm instantly turned off of switching to it when I read that HTML (which isn't HTML and is actually something called JSX) goes in your js files.
With angular I can keep all my HTML in my HTML files. Is this normal or am I completely missing something?
Ask yourself why that bothers you and boil down your objections to a practical point. You can then evaluate whether there is a real cost and whether it's outweighed by other things.
A lot of these issues turn out to be things we learnt were bad ages ago and have forgotten why. The original context you learnt in might be sufficiently different or other factors might mitigate the underlying issue.
In the case of JSX - we were all told that to keep css, js and html separate - that inlines js and styles are bad. These things are all partially true but in a react.js project your components are usually tiny and there is always an inescapable dependence between js and html. It is therefore very different from when we used to see long html documents littered with onclick.
Except that there are use cases where you want to use boilerplate HTML in more than one component (i.e. bootstrap). Also, I've never quite understood the argument that everything that goes into defining a component should live in one file. By that logic we should be putting our data stores in the component, any translations required to internationalize the component, the database queries - heck - why not put the tests in the component while your at it.
The real reason we keep "technologies" separate is so that we understand what realm we're working at any given moment. Furthermore, we can distribute responsibilities across multiple team members focused on different disciplines. Facebook has the kind of clout internally to force their designers to use JSX and inline styles, but many organizations do not have that kind of alignment.
> Except that there are use cases where you want to use boilerplate HTML in more than one component
In this case, you can split out that boilerplate into a separate, smaller component and reuse it inside as many other components as you need.
> By that logic we should be putting our data stores in the component, any translations required to internationalize the component, the database queries.
I respectfully disagree with your inference here - such functions can be abstracted and used by many components - in most cases there's no value in baking them directly into a component.
The exception to this is if the function is not abstract at all, makes no sense outside the context of the component, and therefore can't be reused. Then, it probably makes more sense to put it inside the component, rather than breaking it out into a separate file.
This is true of most if not all of the markup and styles used inside a component, which is why React encourages JSX and inline styles to be put directly inside the component as it's the only place they make sense, and the only place they'll be used. The markup, styles and component behaviour are intrinsically coupled, there is a lot of 1:1 referencing, and separating them out into separate files means you'll just be flicking between three files when working on a component, instead of one. Where there is 1:n referencing, well, that's when you should break your component into smaller, reusable pieces.
I think it's all fine and dandy, and I like the idea of isolated components, but I'm not sold on shoving everything into one file. It just smacks of preference.
So split it up. Most React projects make use of Webpack or Browserify, or use ES6 modules via Babel. There are emerging patterns for keeping concerns in separate places but still having one component you can drop in declaratively.
Then just put all the files for a component into a single folder, which translates 1 to 1. Again, this is all just a matter of preference, and with pre-compilers you could glob all your js/css/html into one file using any framework if you really wanted to. Seems silly to me, but to each their own.
It bothers me because my super intelligent HTML editor becomes useless if I choose to use React.
The reason like Knockout.js because all the magic happens in a standard data-bind attribute, no funky syntax or paradigm shifts required. A purely functional solution like React seems like it's good for making games. Beyond that, for most sites, I think it would be more work to use React for little to no gain.
Knockout is a decent framework, I am using it on a large application currently. It has made some things that would be very hard much easier.
However it has a few issues.
1. Wrapping everything in observables is a bit annoying. Subtle issues can arise here in there especially if using the mapping plugin (which you kind of have to, it makes the process bearable).
2. If you start to have a lot of bindings on a page (a few hundred) performance degrades rapidly and there is a ton of DOM thrashing. Part of the problem is that a binding places an event handler directly on the DOM element. But there is also the initial load "flicker"/DOM thrash which for a significant page can take a second or two.
3. There are lots of workarounds such as rate limited observables, etc... But these are applied individually and become very tedious. They do not solve the entire problem either.
React solves all 3 of these so I can see significant benefits there. I have not switched myself but am experimenting. I do think Flux, Stores, etc.. are very overkill and actually poor architecture. But thankfully there are many alternatives cropping up which are much better.
There are definitely some issues. Regarding the mapping plugin, I managed to build a large custom CRM and accounts payable system without using it, but I did have to build out some custom routines in order to standardize my workflow...
React.js seems like it could be a good core for something like those alternative frameworks that you mentioned popping up. Aurelia looks interesting to me, but I don't think it uses React by default.
Yes, this appears to be the normal reaction to JSX (it took me 3 months to actually try React just because of the idea of it - more fool me).
My advice is to try it at least to the point where you've created a couple of components and rendered one inside the other. A component manages everything to do with how it works with props it's given and the state it manages, and how it renders is just another part of that concern.
One of the nice pros you get used to quite quickly is having your editor autocomplete event handler and data variable names, as they're all right there in the same file.
JSX is just sugar for React.createElement() function calls, the syntax of which otherwise gets quite unpleasant to write and maintain once you start nesting them to any degree (ask anyone who's used a DOM builder library for a complete app).
Once I started using React in practice though, it turned out to be pretty nice. It significantly reduces cognitive overhead when thinking about frontend elements. And if you're worried about your javascript file starting to look more like an HTML file, composition of JSX components helps break things up.
Even if I can't convince you that it's actually pretty nice, you can write React without using any JSX. Just use a live compiler http://facebook.github.io/react/jsx-compiler.html to translate any documentation into the vanilla JS equivalent.
There are plenty of examples in other frameworks, e.g. sometimes view helpers in Rails output HTML. In certain situations it helps you write much cleaner code and it's easier to make more complex view components. Rails form helpers output HTML.
Since it is code that just translates to javascript, it's nice because you can have onClick handlers and such right inline, without having the downsides of inline javascript. You build reusable components that are self contained with their content and their logic. So you know when you use a component, the logic comes with it. You don't miss out on important bindings.
Also i've never really gotten into all the string magic that angular templates use. ng-click="myEvent()", vs passing the event to the component as a property feels.
The concept behind directives like ng-click is actually pretty simple underneath.
The Angular parser will go through the elements in the DOM and look for attributes it knows about like ng-click. When it finds ng-click, it will run the expression "myEvent()" on the controller's $scope.
Yes, i think you miss something important here. It's a tradeoff. You should make your choice based on pros and cons, it's more objective than subjective when you hate something and you don't use it. It's harmful and useless thought:)
I see the point but noone in their right mind would write the javascript like that. When written better it's a good amount shorter than the React solution.
I totally agree, in fact I'm going to link this :) The point I wanted to make is that every feature requires a bit of refactoring like this, whereas React puts some structure.
Makes more sense to me to have the "Tweet" button enabled by default and disabled on load by JS. If there's an issue with the JS or it's disabled in the browser or whatever, the button should still work (with server side logic to catch empty Tweets). Right now, if the JS doesn't load you can't Tweet at all.
Just a small nitpick I had after thinking about the reasoning behind why the OP had disabled the button in JS rather than the HTML in the first place.
true, but to be fair, you'd probably also want to introduce variables like $addPhotoBtn, $tweetBtn, $textLengthLbl, etc, to avoid css queries on every keyboard change. That would add to solution length and also introduce a bind-step to avoid stale variables after a dom change.
Also, there's the authors very well-placed point that adding a new feature may lead to css query refactoring, eg. when $("textarea") doesn't cut it. I find html refactorings to be nb 1 cause for breaking progressively enhanced solutions like this one, probably bc I suck at naming elements.
Lastly, it should be noted that this refactored solution does not contain all the features of the final react solution.
Thank you, great intro to react. Easy for me as a backend dev to follow and get a grasp of React.
One thing, the page loaded constantly itself, after reading half through the tutorial (3-4 minutes), I had about a hundred entries for the same page in the tab history. This makes the website aweful.
Done right you don't really do a lot of mixing markup and Javascript - you'll have a render method which takes your components current state and turns it into markup, with everything else being straight Javascript.
There are ways to avoid it, but I'd encourage you to give it a while before looking for a way out, because almost everyone I know who had that initial reaction has come round to it.
OK I may be off point here - but why do people who know just enough JQuery need to know about React ?
Wasn't React developed as a tool to manage complex data flow patterns inside of a big web app like Facebook ? Why does your average JQuery developer need to know or care about this whole new abstraction layer ?
Even though I've seen it a 100 times by now I'm still amazed by how fad driven programming culture is and I feel like this is a perfect example : React - come learn this complex peace of technology to solve problems you never had (and probably never will).
I thought the linked article actually made the most convincing case I've seen yet for using React for "simple" UIs that you would normally build using jQuery. It demonstrates that even something simple like a tweet box (textarea, character countdown, a couple of buttons) benefits from the React methodology.
Its aimed at JS beginners, a lot of us started with simple web development picked up some JQuery and are looking for something more powerful. This looks like a great segue to building rich front-ends.
In fact if you look at the URL the site is called reactfordesigners.com.
>In fact if you look at the URL the site is called reactfordesigners.com.
You would want your designers to write frontend code that is complex enough to require React ?
The way I've worked with designers is they create sketches and prototypes just to demonstrate the concepts with whatever they are familiar with and then developers turn that in to actual maintainable code with feedback.
My educational roots are in graphic design but I have taken on more and more front end development as my career has progressed to the point that I'm mostly coding these days.
With Web design, I started with simple HTML sites, learned CSS, then learned some JS to manipulate the DOMs I created.
Having run into some of the jQuery pitfalls that the author describes, This tutorial meets me where I'm at and takes me to a new place, using incremental, concrete, and practical examples to show me that React is a logical extension of JS in certain use cases.
Designers are visual people, so being able to see each step along the way and telling me why it's important is a really big deal. I have some projects now where I'm changing state quite a bit, and I can now see where React would be really useful. Designers also tend to get into the web coding stack from the front end first, so I think we end up thinking about coding a Web site in a really different way than back-end developers with a background in software engineering.
The title says
> React.js Introduction for People Who Know Just Enough JQuery to Get By
Unless you're working at a really big shop, designer these days is almost synonymous with UI/UX engineer or front-end engineer. Considering the target audience is JQuery users, React is not too far of a jump and doesn't have to be restricted to "complex" websites.
In order for benefits of React to outweigh the costs you need to have a web application with complex data flow. jQuery is proven to work and there is no problem with it in anything less.
At the point where you actually need React you also need to understand software engineer or you're going to get a mess no matter what the framework is.
I don't think anyone is saying people who know just enough jQuery NEED to know about React, just like jQuery, React is just another tool. To address your points though, React is "A javascript library for building user interfaces", it wasn't developed to be a tool to manage data flow patterns, it was built solely as a view library. Most people pick up jQuery as a means of manipulating their views/the dom so the target audience of both libraries as well as their use cases is very similar. Now I'm not saying the same thing will happen with React, but not too long ago people were saying the exact same thing about jQuery when it was introduced.
React has a significant learning curve and a different model from regular DOM. It has a significant cost over something like jQuery especially when you already know jQuery.
jQuery works just fine at small enough scale. Once you out-scale jQuery you will have problems that won't be solved just by using a different view library - you need to understand software engineering - which is why everyone who actually uses reacts also uses things like Flux, etc.
My point is jQuery works for what it's used, getting people to switch to React seems like a fad because "the cool kids are doing it".
As a front end dev, I love it when people I work with use the right tools, and the mindset encouraged by making React things is just... good. The lisp/scheme/clojure wisebeards would approve of how it makes you think about UI.
I feel as though the move from raw JS to JQuery is similar in significance to the move from JQuery to React. So in answer to your question, I would say a dev who learned React would be more appealing as a hire and as a colleague, and it'd be well worth the investment for any future career.
I've spent ~2-3 years programming in clojure and prototyped stuff in clojurescript. While I love it for the domains it applies and it has influenced my programming considerably - I would never recommend random 9-5 Java dev shop to go pick up Clojure - there's just no point - Java works fine for what they are doing and their developers know it - learning Clojure would be a huge investment and the benefits wouldn't really be there.
The same thing is true for jQuery -> React. If you're a front end designer who does some programming - you need to learn the DOM and CSS, jQuery is just a simple tool to leverage that more easily.
React is a fundamental change that requires a lot of relearning and more importantly the benefits are questionable unless you're dealing with the scenarios it was designed for. You need to have experience with existing tech (that is way more intuitive, like two way data binding) to see what problems it solves - that's not in the domain of a jquery programmer.
I also wouldn't call people who "just know jQuery" devs but rather designers who know how to code.
I don't know why you think React is complex. At its basic form you need to know render method. Its one of the simplist to pickup. I suppose you need to change how you view your page, as a bunch of components instead of dom tags.
I have used it on complex single page app with Flux and without Flux along with simple small components for rails app. Now i don't feel the need to use JQuery but for the very simple single line ops(like hide, show etc). OfCourse i still use JQuery it for ajax.
Novice programmers don't have the perspective to understand that the latest hot library may be old news in 6 months, and how the old adage of "hold a hammer and everything becomes a nail" can impact a project.
A year or so junior programmers figured out how to add Angular as a dependency into every single project whether it was needed or not, now people are teaching them how to do the same with React. The constant parade of new JS frameworks combined with the ease of package managers & compilers is creating a nightmare scenario when it comes to project bloat
I guess the idea is that maybe they'd like to do things that they can't currently do? I'd even argue learning React is more compelling for someone who's never used any of the competing products that for someone who has.
In all seriousness, I've already had to rewrite a codebase because an inexperienced programmer (less than 2 years professional) chose it for a use case that wasn't even appropriate, and he did a terrible job implementing it correctly. My team that took over wasn't happy.
If programmers didn't do stuff solely because it's cool, then that would have been a day back on that project.
Can somebody explain to me what is so bad about jquery? I use jquery every single day to make web pages do the things that I want them to do.
But my javascript hipster friends all claim that this is wrong and stupid and that I shouldn't use jquery because of some abstract reason that nobody ever seems to be able to articulate to me.
There's nothing wrong with just using jQuery. For many, many applications/projects it's a great tool and does everything you need.
What happens as a project/app/site grows is that you add more and more and more jQuery to a single file and it starts to get hard to maintain (hard to find what you want, hard to change something without something else blowing up, hard to navigate the files you're using). Frameworks like React, Backbone, Angular, etc were made to drive large, complicated, often single-page applications where you have massive amounts of interacting code and want to generally simplify what you're writing and how it's architected.
So, in the end, these are meant to help you organize code, be more productive, and have a more coherent architecture. That's the idea, at least. The tweetbot example here is simple because you're just learning so, if this is the only thing you're building on a page, it probably makes more sense to just use jQuery.
I think the typical road from jQuery-only to using a framework is your apps get bigger and you start to think "this is hard to maintain." Then you see an example of a framework doing something that would really help your process and see how it could improve the code you're writing. You try it out, it makes the process easier/more enjoyable, and you continue learning more. Or it doesn't and you swear it off.
AFAICT, these frameworks grow out of a person or team that figures out a more productive way to write code for what they're working on. That becomes a boilerplate they use, then grows into something they think would help others out. Then it gets a name and we all argue about it. In the end, it's just one person's/team's/company's idea of how to write code better, which may or may not work for other people/teams/companies.
There's nothing wrong with jQuery. Aside from extending and abstracting parts of JS and DOM traversal, it also removes many of the complexities with cross-browser support, especially with dated browsers.
The biggest issue is when you take something like jQuery and try to have a multi member team working on a significantly complex and large application. It quickly gets out of hand, messy, and increasingly difficult to maintain. This is without taking into consideration the issues that arise if the developers on the team don't have a basic grasp of how to write jQuery code that still performs well with large amounts of actions/DOM manipulation.
Many interviews for front-end positions also want to make sure you don't only know jQuery, but at least have some grasp on DOM traversal/manipulation without crutches like jQuery.
A lot of the bashing though, is really just from people with a superiority complex instead of logical reasoning. Or it's just people who repeat what they hear, kind of like one of the largest hate trains of all: PHP. Kind of like the story about the monkeys, bananas, and a ladder: http://www.wisdompills.com/2014/05/28/the-famous-social-expe...
1: you can do without jquery, and therefore you should. if all you need is $('#my_id') then it's overkill and it's better to save on download speed by leaving jquery out. See http://youmightnotneedjquery.com/
That said, jquery is a powerful tool and it's widely used for a reason.
2: unrestrained use of jquery, if it's your only tool, can lead to code that is hard to understand, and easy to get wrong. if any part of your code can modify any part of your page, then it is a good idea to retreat from that and be careful/organized about what you do, and when/where you do it. that organization is what JS frameworks try to help with.
you may or may not find your life is improved by such frameworks, depending on what you're doing.
Also interesting to see the pitch on "ClojureScript is a Product Design Tool"[0], written by Precursor's designer. A lot of this stuff can be made more accessible for designers and FE developers who don't want to have to deep dive into all the new-fangled frameworks.
I'm excited for ReactJS catching fire. I've been using a lot of it lately, and most recently I had to go back to a set of components I built to add functionality. In total, the front-end took maybe 20 minutes: no fishing around for the right selector or clashing functions. Just "here's a new button, attach this event"
If you must compare Angular with React,
then at least compare it to ReactJs+Flux+more
or Angular-Templates with React-Templates.
React is more like the view-lib of a framework.
I like them both (also ember, knockout, backbone) and
unfortunately think the battle isn't decided yet.
Will take some time if ever...
Complain to Steve Jobs(1), for killing Flash/Flex, as you
could to client-side apps with desktop performance,
without the hassle of Cross-Browser testing and so on...
In my opinion the concepts of Angular and React+Flux are
heavily based on the features this platform provided.
(1) IMHO the Only good thing he ever did (for the web), as
it forced the proprietary software out... but led to the
great Framework-War :)
P.S.: Also Actionscript 3 was ECMAScript(Javascript) plus Classes, Types and more... ( I wondered about which
Version that was latly and found out they implemented
ECMAScript and extended it with features requested by
users.)
This tutorial is awesome! I love the tone and how it knows EXACTLY who it is written for.
This may be a bit late, but I would LOVE for someone to do this for JS in a Rails App (or even CoffeeScript). I am desparately searching for good tutorials for people that are "borderline-decent" at jQuery but are Rails devs. I can't find any.
I understand, in theory, how to render some JS on a view and all this good stuff - but once you go into creating a UI that feels like a modern UI with lots of lil AJAXy elements...it can become a pain REAL quick with a bunch of `...js.erb`s all over the place with no seeming pattern to them.
So I would love if someone had a tutorial just like this, for how to create a simple and sexy app that looks like an Angular/Ember app but just using CoffeeScript/jQuery/vanilla JS.
I think the problem lies in the '.js.erb'. Write javascript in separate javascript files (in app/assets/javascripts/) and use JSON to get data from the rails backend.
Also unless you really like coffeescript, stick with javascript. If the syntax is bothering you, you can write in ES6 (next version of javascript) which has nicer syntax and use babel to convert to ES5
I hadn't seen todomvc but it doesn't quite address my issues. It still feels too disconnected from where I am.
Also, I do write JS in separate JS files - but my understanding is that when you want a response to be in JS, don't you have to use a corresponding `...js.erb` file to handle the action/response?
How else would you update the DOM after the action has been completed?
The json the code fetches is static but it can be served by a rails app. The DOM manipulation gets painful which is the reason people adopt JS frameworks.
Great concept (tutorials for people who know just enough JQuery). Would love more tutorials (for Angular, e.g.) for such people.
TodoMVC was a great effort. But unfortunately, the actual Todo creations are not well documented (for beginners to figure out how and why certain things were done).
This is really neat.. one thing though: there is nothing magic about 'the "magic" state'; it would IMHO be better to just call it state (or inner state, or so), and to explain that once the state is changed react rerenders the component automatically.
I think this article demonstrates very well why I think React should be the first choice for any new web projects... what to go with it (ember, flux (and related), or other) is open to more debate.
Of course there are great alternatives with similar workflows (mercury, etc).
I think this sums up React.js perfectly. Easy to learn and build something with, but the discussion around Flux and what libraries to use to implement it can complicate and deter newbies. The official explanation of Flux on Facebook's own site I think does a poor job explaining it in a way most developers (new and senior alike) can understand.
That's very fair, it gets even more complicated when trying to do server/client mixed rendering with it. It's all very hard to grasp in a deeper level.
This tutorial is absolutely awesome.. and I think the deep dive is worth it for larger apps too.
This is the first React article I read where it actually compares and contrasts the jQuery approach and the React approach. I feel like React makes sense now, even though writing my HTML inside JS still feels off.
am I the only one fine with using just jQuery and ajax? I've written a chrome extension with 4k lines of code and I never had any problems. Instead of breaking things into separate classes and components, I just put them in separate files or in logical sequence. I'm sure this can get a lot messy with more than one developer but so far my projects, I almost always just use some jQuery library or plugin that does 80% of what I want to do and hack the rest.
Nope, you're not the only one I agree completely. I'm tired of what seems like an endless supply of new, mega-hyped frameworks that seem to provide only marginal improvements.
I'll take the time to learn something new when it is truly groundbreaking but until then I care more about the end product than what was used to make it.
That is pretty much where every frontend dev starts out and then quickly realizes that as your codebase grows and you have different types of data and events firing back and forth, things get unwieldy fast. I'm sure you think your 4k lines of functions across however many files works for you, but I think if you really take the time to learn one of the good JS frameworks, you will be amazed on how much cleaner and robust your code will become.
In all seriousness I typically work with a lot of designers; asking them to update markup in JSX versus HTML is simply not possible. It's not because they can't figure it out but it makes it more difficult for them to quickly test and they typically break JavaScript in many, unexpected ways. While I'm fine with the UI and business logic separation where UI can contain markup _and_ scripting, I don't think the answer is this awkward solution of shoving HTML into the scripting.
This is what worries me. We are using Angular, and my non-technical co-founder knows just enough HTML and CSS that she makes a very useful contribution to our front-end development. Sometimes the contribution is in the form of HTML mockups produced outside of our app that are easy for me to port over, and sometimes it's direct contributions to the codebase. I worry that if I went the React JSX route that it would be much harder for her, or pure designers that we might hire, to meaningfully pitch in.
My understanding was that forgoing JSX would make the situation worse by falling back to imperatively manipulating the (virtual) DOM within your component. If there is a way to have an external, declarative HTML document using React I would be very interested.
This is why I've implemented a prototyping framework at Catalyze that's built with Angular, the same framework we use on the production front-end.
The flow typically looks like this:
1. Create conceptual wireframes
2. Build static UI components (typically in sketch)
- This step helps us define the look and feel of the product before jumping into code. However these are not full page mockups. It's more like an internal UI kit, and for the most part, it's fairly standard across products. So we don't have to update it often.
3. Build the styleguide from the UI kit in Sass (within the framework)
- Again, this is fairly standard so it's mostly templatized. We have an internal UI styleguide that's built already. So most of the changes per product are minimal (they're mostly small tweaks to give each product more character).
4. Build the prototype (within the framework)
- Since we use a template for each new prototype things like routing and more complex Angular concepts are already set up. Because of this designers aren't forced to approach the steep part of the hockey stick. They can stick to the view layer.
Sure you can be productive as a single developer. The problem is when you're handed a project from another single developer-project, and the project is a hot mess of spaghetti jQuery where business logic is intertwined with DOM manipulation.
It's basically impossible to work with unless you've created the code yourself.
Do you have an example of a large web application that uses just jQuery and tries to achieve single-page-application type UI?
I ask because I'm a backend (Django) dev looking at upping my frontend chops (having previously used jQuery and ajax to glue things here and there), and I'm overwhelmed by the choice of frontend frameworks at the moment. I'd love to see how a big jQuery project is set up.
Particularly terrified of making a time investment and finding out that my chosen framework is no longer the hotness of the week. Because, support and community and stable API's count.
One project that I work on has a non-trivial front-end (it’s around 50K lines of code) that has been successfully maintained for quite a few years now. It predates all the current trendy JS frameworks becoming popular, and HTML5 for that matter, so instead it uses jQuery and jQuery UI for the basics, along with a Java applet for some graphical aspects.
Based on that experience, I smile a little when I see people claiming that you can’t build significant web apps without a modern framework. Of course you can. The architecture for the app I mentioned has something close to a traditional MVC structure, uses a simple observer system for keeping everything in sync, and generally follows good modular design practices. Nothing about writing code for a web front end magically breaks all the UI ideas we’ve been using successfully in other environments for decades, and people have used those techniques to build UIs vastly more complicated than any web app ever written.
That all said, it’s also true that as the interactions between different parts of models and the rendering of views becomes more complicated in a UI, writing manual code to update the DOM via jQuery becomes tedious. I thought this article summed up the problem quite nicely with the code snippets and diagrams showing potentially SxR relationships between state and rendering when you manually and directly update the latter, compared with S+R relationships when you isolate each side with a good architecture.
So, I’d say the more interesting question if you’re building a not-small web app is whether you are better off building your own architecture or reusing someone else’s. That has the same trade-offs as any other framework decisions in programming; again there is nothing special about writing a web-based front-end really. On the plus side for a comprehensive framework, you get a lot of basic things much quicker than writing them yourself, and the popular frameworks have huge ecosystems built around them so a lot of not-so-basic things can be had relatively easily as well if you need them. On the minus side, in practice you will forever be constrained to work as the frameworks want, which can become a heavy burden later on if you do need to do things that aren’t a perfect fit, and you are locked into external dependencies with uncertain long-term support.
Something I find interesting about React is that although it’s often compared with big front-end frameworks like Angular, it’s really closer to a library than a framework. Fundamentally, you use React to do exactly one job: manage the rendering and events within a specific part of the DOM. It’s agnostic about where any underlying state comes from, what triggers updates to that state, what you’re doing in response to any events, or what you’re doing anywhere else in the DOM. The entire API for React doesn’t quite fit on a single screen, but a minimal working example only depends on three functions that feature in React’s defined interfaces, and even in real production code you probably won’t use more than a handful.
So if you’re the kind of developer who is concerned about bloat and dependencies but also wants to use good tools instead of reinventing the wheel, a library like React is probably a reasonable compromise between retaining control and long-term flexibility in your code but also automating things you really would waste quite a bit of time on otherwise. I suspect this balance is the main reason why it seems to attract favourable comments from a variety of developers, including those who generally don’t like the heavier frameworks and all that comes with buying into them.
Just by way of completeness, probably the most controversial aspect of React is the way it winds up with its version of HTML templates being embedded directly within the JS code (with some optional but convenient syntax that a preprocessor turns into real JavaScript). You aren’t likely to be getting one person/team designing your mark-up and styling and then having a separate person/team implementing your JS coding if you use React. In this respect it does also come with a degree of lock-in, because transferring those mark-up/template assets to another rendering library or framework later would be a chore. However, that’s somewhat true for most other template-rendering tools you might use as well, because they all tend have their own syntactic quirks, so I’m not sure it’s really worse than other reasonable choices you might make.
So in summary, you certainly can build web apps using manual, direct DOM manipulation via jQuery and the like, but you will also wind up inventing much the same kind of tools that many of these frameworks provide to a degree. There is a balance to be struck between retaining full control and flexibility vs. using good tools, just like any other programming with libraries and frameworks. As for React specifically, it really sits closer to the library end of the spectrum than a lot of modern JS frameworks, so if you do want a modern tool to help with rendering and managing events in your DOM but don’t like the big framework lock-in, it’s probably worth a little of your time to investigate whether it’s a good choice for your project.
> again there is nothing special about writing a web-based front-end really.
I thoroughly disagree. There are a lot of challenges and opportunities with web apps that you do not have in the same way in other UI environments. Having a way of enumerating different states of the application, and jumping between those states (URIs) is just one.
> Having a way of enumerating different states of the application, and jumping between those states (URIs) is just one.
Most web apps treat different routes as different screens, effectively, to use a piece of jargon from a bygone time. A URI is usually just a parameterized screen; IDs in the URI determine which bits of data the app is viewing / editing, no more or less than parameters to a Visual Basic or Delphi form.
There are a lot of challenges and opportunities with web apps that you do not have in the same way in other UI environments.
Can you suggest a few others? I don’t see how the issues that arise with the example you gave are any different to things like parsing command line options or acting on shortcuts in native UIs.
I think part of it has to do with the fact that web development is a very large and diverse field. It's very possible that the types of projects you work on do not require a different approach. For example a web application with a large about of UI elements. Or very specific client requirements. Or a continuous cycle of iterations over time. Or a common structure for a team.
Indeed the old web dev write once, pass it to the client and never see it again has quite a bit of difference in requirements to the large scale robust web application that needs to be able to survive a long period of iteration and maintenance.
Imagine being solid at design, pushing pixels, using HTML, CSS. Then suddenly these program frameworks which are created by back-end programmers not visual designers appear and the ramp up for the average technical person is immense. For me it's been enough to turn me off them all together and make it a talking point that "my javascript skills fall off at X,Y or Z" so recruiters and employers know that despite being able to do a lot, I can't suddenly become everything UI and everything back end just because the title of anything "front end" is so versatile.