全ての 119 コメント

[–]regular_reddits 97 ポイント98 ポイント  (16子コメント)

1.React proponents would tell you that forcing yourself to separate HTML and JS (presentation and logic) is more of a separation of technologies rather than concerns. If you think in a React way, the concerns of the application will be small composeable components. Each of these components does a specific thing, and from this is where the real separation of concerns comes.

In the classical model its pretty difficult to not tie your logic strongly to your templates by using selectors, which makes so that if you change one of them you have to change both.

2.If you are worried about JSX, you can write React apps in pure javascript. JSX is just sugar. However, youll probably find JSX a little simpler to work with.

Also, Most applications now days have some sort of build step already. Maybe browserify, maybe minification... something. If thats the case you can just tack the JSX build on.

I didn't give react any attention when it was first released because of these concerns. Its approach is very different, and not what I was used to. This article was what got me to give it a chance at first.

[–]Something_Sexy 19 ポイント20 ポイント  (8子コメント)

Holy crap, that article you linked to has the coolest concept ever for showing examples + working demo.

[–]wdpttt -1 ポイント0 ポイント  (7子コメント)

I can't see any

has the coolest concept ever for showing examples + working demo.

here http://jlongster.com/Removing-User-Interface-Complexity,-or-Why-React-is-Awesome

Where exactly should I look at?

[–]spaceghost0r 1 ポイント2 ポイント  (6子コメント)

As you scroll down, demos appear in a green pane on the right-hand side for you to interact with.

[–]wdpttt 5 ポイント6 ポイント  (4子コメント)

I had js disabled, sorry about it (:

[–]qBorreda 18 ポイント19 ポイント  (2子コメント)

Give this guy some credit!! He is posting at /r/javascript with JavaScript disabled!! :P

@munrobag please don't take offense - I just thought it was hilarious

[–]RagingNerdaholic 1 ポイント2 ポイント  (0子コメント)

NoScript master race!

[–]wdpttt -1 ポイント0 ポイント  (0子コメント)

After you see what crypto wall does you will do it too (nobody said that crypto can enter with js, but I don't really trust them!) . I just disables js by default and enable only when I really need it and on sites I almost trust.

[–]munrobag 0 ポイント1 ポイント  (0子コメント)

I just get a shitload of js errors:

http://i.imgur.com/4TTMB4X.png

[–]foxh8er 3 ポイント4 ポイント  (1子コメント)

So instead of creating UI elements and then hooking them up to JS you just create the UI elements as JS objects?

If I'm understanding this correctly this is cool as fuck. Might just use this next time.

[–]fooey 3 ポイント4 ポイント  (0子コメント)

It's web components / polymer, except it works now, and it's damn fast.

[–]angus_the_red 2 ポイント3 ポイント  (0子コメント)

You are so right about #1. Modularity over layers.

[–]Ncksllvn[S] 2 ポイント3 ポイント  (3子コメント)

React proponents would tell you that forcing yourself to separate HTML and JS (presentation and logic) is more of a separation of technologies rather than concerns.

I agree with this, and I actually like that concept. But when integrating a CSS library, I think it could be troublesome to have your logic exposed when you're only editing HTML. Like when Bootstrap was updated from 2.3.2 to 3, everything changed. It seems much more comforting/convenient to have files containing pure HTML to modify, especially if it's they're being modified by another developer/designer who doesn't write a lot of JS (referring to devs who write purely HTML and CSS.)

With that said though, it is definitely possible that they could still break the component without seeing the JS.

[–]html6dev 11 ポイント12 ポイント  (0子コメント)

All of the ideas like this against react are the things people think 'in theory' but are usually not grounded in reality (i.e.in practice, actually building things). Consider this: you've chosen bootstrap as your css framework. You'll be using a lot of row and col classes so you make a column and row component. Hey look at that! I can swap out css frameworks completely and change the class names in one place. That's such a good idea I may want to use it in tons of projects (someone's already got a mixin https://clozeit.wordpress.com/2014/01/08/13/).

The issue of markup in code is similar. Why are you so concerned? These are functions not actual markup, but there are some amazing benefits to being able to refer to components as markup in a language that has higher order functions...The entire point is they are functions and therefore we can take advantage of the composability a sort of functional language provides. JSX simply helps you model the system more easily, and that is a very good thing. Ultimately, if it increases productivity, composability, performance and maintainability (far simpler mental model) how is putting js in your markup ala Angular superior to putting 'markup' in your js?

Finally, which one of these frameworks is used in one of the world's most widely used Web Apps vs (at best) small internal tools by their corporate stewards? (and xhp was the same concept in php and being used in prod by Facebook many years before the thought of react was even conceived). Thats real life proof it can be used in products with some of the highest demands that exist as far as scalability is concerned. When I think about doing my job (delivering scalable, quality software) that's not much that makes me think the term 'great' than that. In summation I just want to say: try it. It hurts nothing and it will give you a different way of viewing how you structure your apps which is always good. If you build something non trivial like a todo list and you find you hate it, you've lost very little, but you might be surprised to find you love it (I had the same markup reaction right when it came out but realized I didn't actually have an argument that fit react when I really dug into it. It was just an ingrained mental model that reacts goal is to change).

[–]regular_reddits 7 ポイント8 ポイント  (0子コメント)

Yeah, integrating with CSS is different in react for sure, as far as something like bootstrap is concerned though it isnt too bad. Bootstrap's css is already separated into components. So you would create a react version of each of the bootstrap components (or just use react-bootstrap) and the rest of the app's higher level components would be composed of these bootstrap components. When updating bootstrap, your changes are just in your bootstrap related components. Its still an issue when you want to use someone elses generic component (that doesn't expose classnames on the inner elements) with something like bootstrap as far as I can tell.

[–]baddox 4 ポイント5 ポイント  (0子コメント)

I think it could be troublesome to have your logic exposed when you're only editing HTML.

That's true, but that inevitably happens even when you're using something like Angular directives or Ember Handlebars. Modern JavaScript-heavy web applications have inherent coupling between the description of DOM and the logic of the application, because the logic of the application determines the DOM (i.e. if your application JS is one big function, its output at any given time is the state of the DOM at that time). React realizes this and hits it head on: you literally use JavaScript (and JSX sugar if you prefer) to describe the DOM of your application.

[–]danneu 21 ポイント22 ポイント  (3子コメント)

> HTML directly mixed in your JS mixes the
> presentation layer with your logic, breaking 
> separation of concerns.

But UI presentation and UI interaction are closely intertwined. Ever work on a project with index.html and then one big app.js of jQuery select/trigger soup? That's not separation of concerns. That's just indirection. Proof: Change index.html in a random way. You'll have to check app.js to see if it broke anything.

[–]ramblerman 4 ポイント5 ポイント  (0子コメント)

That's a really solid argument I hadn't considered. The illusion of separation indeed.

[–]Martinspire -1 ポイント0 ポイント  (1子コメント)

But what if you work on it with a lot of people and have a big project? Separating the project in various files seems like a good thing then?

[–]BosolaI still like Knockout.js 0 ポイント1 ポイント  (0子コメント)

Implement your page as a series of components. Each component has a file for its class.

[–]spergery 13 ポイント14 ポイント  (0子コメント)

There's no HTML in your JS. There's JSX, which includes HTML-like syntax as syntactic sugar and compiles to vanilla JS (and it's helpful, but not required). Also, it's not really "in your logic", it's in your presentation layer. What React does differently is that your presentation layer comprises both how a component is structured, and how it reacts to changes. The separation of concerns is between components and business logic, not markup describing how components are structured and javascript describing how they behave.

it's only popular because Facebook made it.

It was extremely unpopular when it was first announced, and a whole lot of people thought facebook was incompetent/insane for inventing it. They've mostly come around.

[–]UgnisKarolis 27 ポイント28 ポイント  (17子コメント)

only popular because Facebook made it.

Nope, because React is awesome. It does look like an ugly duckling at first. My thoughts were exactly like yours before I started using it.

HTML directly mixed in your JS

Sounds terrible right? Having HTML, CSS and JS in separate files is separation of technologies not concerns. Having everything in one place lets you see how the whole component will look like in any given state. And that's the magic of React. (more on that at the end)

.JSX files

You don't have to use it but it is very useful. React code generates HTML. Writing down JSX makes programming faster because you can see what HTML is going to be generated. We are already used to changing layout in HTML.

React still sound like a bad idea. And it probably is not an ideal solution. As I said two years ago about Angular, that's the best we've got. Reacts code separation into components, excellent v-dom and single directional flow (flux) support makes it one of the fastest development tools for web apps.

TL;DR MVC was a terrible idea for big apps. Developing apps with React looks ugly only at the start.

[–]icanevenificant 8 ポイント9 ポイント  (12子コメント)

I'm with you most of the way but how is MVC a terrible idea for big apps? What is so terrible about it?

[–]UgnisKarolis 10 ポイント11 ポイント  (8子コメント)

This might just be me but then again my work is rewriting big apps from angular to react.

Most big Angular apps look to be hacked together with a duct tape (models intertwined with views in so many ways that the app is impossible to understand). This is no fault of the MVC that just tends to happen given enough time and no rigid structure. The problem with MVC is that every new person, every back-end engineer can start writing "good" code that generates insane amount of technical debt. In a perfect world this could be avoided but alas, now I have work for the rest of my life.

React on the other hand forces separation of code into components. Components can be read and understood without reading the rest of the program. Components can be deleted and rewritten again without any impact on other parts of the program. I can feel safe adding new functionality to a massive react program. And I feel like I am in a minefield when working with Angular(still miles better than the jquery spaghetti we used to write)

MVC is not terrible as a concept, we, programmers, are terrible at executing MVC when the scope gets too big. And React solves this problem.

[–]right_in_the_kisser 5 ポイント6 ポイント  (1子コメント)

sounds like a problem of Angular, not MVC? Also, I hate to be that guy, but angular is not based on a classical MVC pattern.

I also have experience in working with large angular apps, and you're right - I find angular being quite problematic for larger codebases.

[–]html6dev 4 ポイント5 ポイント  (0子コメント)

The issue with 'classical' mvc which unless you are writing old small talk apps, means model 2 over http these days., is that it's an adaptation of the original mvc built around a stateless protocol. The client isn't stateless and most of the complexity revolves around state. This is why we have all these weird quasi mvc patterns trying to be shoe horned in to a paradigm they never fit well with to begin with. Managing statement in an extremely simple and straightforward way is the intention of react, however.

[–]powertopeople 4 ポイント5 ポイント  (0子コメント)

So, I've never written, really seen or read up on react.js, so I can't make many comments on that particular framework. But I do write AngularJS every single day, and I very much disagree with your assessment of MVC being bad for large scoped applications.

As with any language or design pattern, you can royally screw yourself and your future development partners by being undisciplined. I think the valid criticism of AngularJS is that it doesn't force you to do anything, and as such you can very easily end up with a spaghetti of code. In one day, you can go from clean, simple and elegant to messy, ugly and complex. But, this has nothing to do with whether or not a clean MVC implementation in AngularJS isn't scalable, it has to do with how disciplined you (and your team) needs to be to implement a well built AngularJS app.

From my perspective AngularJS is best used (even for large scope applications) with an MVC and services oriented architecture. If every major piece of functionality is wrapped in a service, and then each controller is simply connecting various services in a custom way, then your application becomes incredibly simple to understand for new developers. If you code logic into your HTML templates, then that's your fault as the developer for not following good coding practices. In reality, the cleanest controller would have some set of view states that define what's visible or not, and then your HTML contains a few ng-show="viewConfig.showChart1" elements, and boom, your code is fully understandable just by scanning the controller.

This is fully done with strict MVC and a services based approach. In my opinion, it's the best way to use AngularJS. Couple that with well designed reusable directives and AngularJS is one of the most flexible frameworks available. Granted each directive in itself breaks MVC, but as a whole MVC is followed.

As a side note in defense of MVC, it's one of the better ways to make apps scalable. In my experience most of the scalability issues come in parts. The data model isn't flexible enough for example. So do I need to re-write everything? Or just the model? What if my UI ends up having a million lines of scrolling because I didn't anticipate the size of my data set? Well, I need to implement a filter or paging, with MVC I know exactly where to go to make these changes and don't end up touching code I don't need to touch. Which leads to fewer bugs, higher maintainability and easier ramp up time for new devs.

[–]dvidsilva 4 ポイント5 ポイント  (3子コメント)

there are ways of writing Angular apps like that, in a way that they don't look hacked together. unfortunately Angular doesn't enforce you writing good code and the resources to learn properly are still limited.

is like the php of JavaScript frameworks :P

[–]nschubach 1 ポイント2 ポイント  (1子コメント)

Directives? They still fall short, IMHO. The two way binding capability of params makes debugging troublesome. Anyone can inject some random service and update something that shouldn't be done... Circular reference injections. Oh, you wanted that directive on that element? It's too bad the Dev decided to add a dependency on your session service and that depends on this other service that depends on ...ugh.

[–]icanevenificant 0 ポイント1 ポイント  (0子コメント)

But this again is just a consequence of lack of discipline and standards. It's not the fault of framework in my opinion if people misuse it.

[–]dustrider -1 ポイント0 ポイント  (0子コメント)

This is probably the best analogy I've seen on angular. good one.

[–]elprophet -1 ポイント0 ポイント  (0子コメント)

Two way data binding MVC in the Rails N-tier stack can be meh. Real MVC from the Smalltalk days is what Flux re-invented, and the single flow of state mutation is a big win. https://medium.com/@davidsouther/song-flux-e1f9786579f6

[–]madman86 -3 ポイント-2 ポイント  (0子コメント)

Check out this for more on why MVC isn't good for large, complex applications: https://facebook.github.io/flux/

[–]Omikron -3 ポイント-2 ポイント  (1子コメント)

Mvc is not terrible for big apps you have no idea what you're talking about.

[–]DustinEwan -5 ポイント-4 ポイント  (0子コメント)

Said nobody.

[–]fzammetti 9 ポイント10 ポイント  (12子コメント)

It's funny... a few years ago I introduced my company to a relatively new product called ExtJS. I pushed hard to have what was (and still is in fact) our largest, most complex, expensive and mission-critical app built with it... truly, it's an app that makes most others look like child's play in terms of complexity and size, and it it failed today there's a good chance we'd take the business down with us.

At first, there was A LOT of apprehension... "we're mixing concerns!", "there's no separation of layout and code!", "it's a return to building UIs with code rather than markup!", and so on. It took a number of presentation, prototypes and proof-of-concepts to finally win approval, but I did.

Fast-forward a couple of years and now my multi-billion dollar corporation of thousands of developers use ExtJS almost exclusively across the board and there's a general feeling of "why would you do it any other way?!" I can't claim sole responsibility for that, but I most definitely played a big part, but it was an up-hill battle in the beginning for sure.

I'm not trying to evangelize ExtJS here... some people love it, some hate it, and I'm not trying to have that debate here... what I AM evangelizing though is the approach to app construction that it naturally pushes you towards. I mention this only because as you look at React, while it's not exactly the same thing, there's a lot of similarity... certainly to the extent that it eschews a lot of the "conventional wisdom" of the app development community at large.

It's an interesting shift, as someone who's been in this field for more than two decades now... I think there's a shift starting to occur, an architectural mindset change, and React is definitely a part of it. It definitely takes some effort to get your brain wrapped around the underlying concept ESPECIALLY when it seems to go against a lot of ingrained "best practices"... but if you can get past your own prejudices you'll likely find the approach has a ton of merit (whether you like the particular React implementation or not).

[–]sprhoto 2 ポイント3 ポイント  (2子コメント)

I think the ExtJS to React analogy is interesting, but let me throw another analogy to consider...

Remember like 2007/2008? Ruby suddenly starts running rough shot over LAMP for web design. But, there were a crazy number of frameworks - Rails, Merb, straight up Rack, and on and on. Eventually, Rails basically won that battle. The point is, when a new technology becomes a Thing(tm), how to best build around a technology becomes a problem, and everybody thinks they need to build a solution. That's where we are with Node and async programming right now. People have realized it can solve problems other technologies can't but nobody exactly knows how to do it best. So, we have Ember, Backbone, Angular, React, Meteor, and on and on.

I bet in 4 years there is only React vs. Angular with Web Components and we are wondering what all the fuss was about.

[–]fzammetti 0 ポイント1 ポイント  (0子コメント)

Definitely could be true. I've seen that sort of cycle repeat a number of times in my career and I have no problem believing it'll happen again. Whether it's really React vs. Angular or not I don't know... I personally don't feel like either is the right answer, however, if that winds up being the consensus than so be it.

[–]FilthyCasualCoDKiddy 0 ポイント1 ポイント  (0子コメント)

there were a crazy number of frameworks - Rails, Merb, straight up Rack, and on and on. Eventually, Rails basically won that battle.

This is not really accurate. Rails, merb, and sinatra were competing frameworks (there were a few smaller ones that didn't get much share, I remember the camping framework specifically).

Rails and merb merged (2008), to make the best of their design choices. Sinatra was super bare-bones and doesn't need features (that's the point). So really there were (are) two frameworks, and they're not competing.

Rack is a webserver interface that pretty much all ruby frameworks now implement so that you can use any rack-compatible application server (thin, puma, unicorn, apache's phusion passenger, etc) to run a rack-compatible app. It is not and never was a framework.

As far as rails "winning" - there was never any competition. Rails started out being the killer app (by 2.x) and has only gotten more adoption. It wasn't really a competition. If you want to build a super simple web app or site, sinatra or padrino (a layer of abstraction on top of sinatra) will do. If you need routes, db access, etc, you want Rails. There hasn't really been anything else since 2008.

[–]defcon-12 0 ポイント1 ポイント  (8子コメント)

There is no similarity at all between Ext and React/Flux. React forces you to separate your concerns. React is only the View. ExtJS just gloms everything together. Many Ext UI components directly interact with Stores (the model in Ext) or use the Stateful mixin, which tightly couples UI components to model logic. Ext components use manual DOM updates, but NOT doing this is by far the biggest selling point of React.

Ext also uses fragile inheritance to extend components, while React uses more robust composition to extend components. Ext also has it's own slow and crappy JS layout engine, while you just use CSS or inline styles in React, which is massively easier and more performant.

Ext is "the old way" to do things from a time when devs tried to make the browser act like a desktop UI framework, while React uses all the advantages the browser and DOM has to offer. But really the reason you shouldn't use Ext is that it is slow as balls, and you'll spend crap tons of money attempting to optimize it.

[–]lechatsportif -1 ポイント0 ポイント  (5子コメント)

I like react but build a fully feature complete extjs grid with it and then claim victory. React is just a rendering layer

edit: a grid is not just a table like arrangement people. Go look it up!

[–]mrmass 4 ポイント5 ポイント  (0子コメント)

Maybe in 2009 there was a need for that, but now we have flexbox.

[–][削除されました]  (3子コメント)

[deleted]

    [–]fzammetti 0 ポイント1 ポイント  (2子コメント)

    Why in the world would you WANT to build a grid from scratch?! The grid in ExtJS is the most robust grid I've ever seen, implementing even a quarter of what it gives you out of the box in ANY technology is a fools' errand.

    You talk about ExtJS being slow and I can only assume you used an old version. Ever since v4 (the previous version now) it's been fantastically performant in virtually any use case, the grid for sure.

    [–][削除されました]  (1子コメント)

    [deleted]

      [–]fzammetti 0 ポイント1 ポイント  (0子コメント)

      I don't know, that just doesn't match my experience. I've explicitly had our developers NOT create custom components or ever modify core ExtJS code, it's almost all stock, and we don't have these issues... in fact, until the middle of last year our corporate standard browser was -gasp- IE6... and even with it, our performance has rarely been an issue (only times I can think of where it has been is when we tried to dump 1000+ records into a grid... but that's a usability issue regardless of ExtJS performance).

      Eh, whatever, we're probably boring the React folks at this point :)

      [–]fzammetti -1 ポイント0 ポイント  (1子コメント)

      Re: gloming everything together... this is only true if you have no discipline in your own architecture. I would accept that ExtJS makes it easy to do that, but the coupling is actually quite loose these days.

      Re: Fragile inheritance... I'm not really sure what you're referring to here. Can you provide an example?

      Re: Speed... have you used v4 or v5? This is no longer a valid complaint. I would grant you that ExtJS may have a limited application in the sense that it doesn't perform so well on mobile browsers, which is a much bigger target than it used to be... but on a desktop it's just not slow anymore. I wish I could show you the app my team has built with it because it would dispel any performance concerns you have. The crappy layout engine you refer to isn't crappy anymore (if it ever was) and the sheer power it provides makes everything else, plain HTML and CSS included, look positively arcane.

      Re: "the old way"... I would argue it's in no way, shape or form the old way to try and create webapps that look, feel and function like desktop apps. In fact, it seems like most people are doing exactly that regardless of what technology they choose to use. Heck, we even have Phonegap to make our mobile webapps work like native apps (a native mobile app is analogous to a desktop app in the sense that it's an app targeted for the specific platform it runs on).

      As I said, I definitely don't mean to turn this into an ExtJS versus anything else debate... we can do that elsewhere if you'd like :) But I wanted to respond to these specific points because my experience tells me they just aren't valid anymore (they may have been in earlier versions, but not now).

      [–]defcon-12 2 ポイント3 ポイント  (0子コメント)

      My experience is with v4. Classes like the grid break proper separation of concerns by interacting directly with Stores straight out of the box, behavior that is better encapsulated in some type of controller layer.

      An example of fragile inheritance is something like the TreeGrid where the view is like 5 levels of inherited classes, hope you don't want to change a behavior that's 3 levels deep and all the layers on top depend on.

      Performance may be ok for internal webapps, but it is certainly not up to consumer standards. For example scrolling with buffered renderer and variable row height remeasures every row, causing an Ext layout for every scroll event and a browser reflow for every single rendered row.

      Take a look at the grid that was announced at React conf. Doing something like that in Ext and making it performant would be just about impossible.

      I'm glad it works for you, but it's been my experience that Ext is extremely costly to optimize and customize, where as React takes some initial investment since it has no "out of the box" functionality, but optimization and customization is dirt cheap, because it's very simple.

      React's learning curve is vastly shallower and much easier to get a large dev organization up to speed. The api surface area of Ext and the knowledge required to optimize it (like debugging layout cycles) is enormous, and getting a 100+ person dev organization trained and on the same page is a very daunting task.

      [–]RazorCrusade 4 ポイント5 ポイント  (0子コメント)

      I'm another who thought React looked asinine and kinda refused to use it at first. But I ended up with a project where I needed to create an embeddable JS lib and realized there were no great solutions for including the necessary DOM the lib needed on the page, so React was a natural choice since the "DOM" is included in the JS.

      I quickly came around to it.

      As others have stated, there is no real separation of concerns. If you're using jQuery in your JS, you're already doing the same thing React is doing. And if anything, keeping everything componentized makes it much easier to work on a project since you don't need to find a bunch of disparate files all of your codebase; it's all in one place. With Backbone, your JS is tied directly to some DOM object somewhere, but depending on how it's written, you may need to look in half a dozen places to find all the necessary files. With React, it's just right there where you expect it.

      It also forces you (or tries) to get rid of event emitter hell. I, personally, don't really mind largely event-driven applications, but I also can understand that they can be very difficult to trace and understand. If you're using one-way dataflow, you don't have these problems. You know exactly where data is coming from and there it's going.

      As far as an additional compilation step... I've always been of the opinion that the less magic bullshit you need happening as a front-end dev, the better. But honestly, you just set up the watcher in a screen/tmux or as part of whatever other build process you have and never think about it again. The annoying-ness of it is really overstated.

      [–]trollingisfun 28 ポイント29 ポイント  (7子コメント)

      conversely, what's not great about React.js:

      1. constantly changing component/element API if you don't use JSX transforms (e.g. you don't want to use the whole npm + webpack/browserify/jsx-tools transform+bundle+bootstrap+compress workflow)

      2. slow behavior when constantly recomputing object trees (you can solve this with diligence with data manipulation and shouldComponentUpdate OR use ImmutableJS or something)

      3. awkward ass "class" definition with objects (improved/fixed in 0.13)

      4. stupid mixins (largely removed in 0.13)

      5. virtual DOM (it's really just an implementation detail, if browsers got their shit together, it could really just do a digest or anything)

      6. first-class consumption still uses this horrible browser language (though, CLJS/Om is godlike, so there's that)

      7. hyped up, but not as much money making opportunity as angular and ember (not as easy to integrate and just shit into your project -- the opposite is true also, easy to integrate react components into existing projects)

      8. most people fucking suck at writing JS/programming in general, and letting them just write JS makes it hard to fix and enforce structure. not a problem if you're a small shop or you quality control your devs, but in a "big company"/average corpo shop, this will fuck you

      9. stupid JSX/react style attribute names, because of camelCasing fashion freaks

      10. PRs sit in GH for months before ever getting a response, makes you wonder when X bugfix you see on GH is ever going to get merged

      ...but overall still better than almost every other npm-listed/JS project, so it's really fucking good

      [–]angus_the_red 4 ポイント5 ポイント  (0子コメント)

      I like your style. Fiery.

      [–]koglerjsIt's 'Javascript' - 'JavaScript' looks funny | koglerjs.com 1 ポイント2 ポイント  (0子コメント)

      7's an interesting point; though not really a React fan, I'd still be happier seeing React on job postings than I have been seeing Angular everywhere, and React isn't as much of an 'enterprise solution' so it might not get to that point.

      [–]nschubach 0 ポイント1 ポイント  (2子コメント)

      Is this a troll post (as the name insists?)

      stupid mixins (largely removed in 0.13)

      Mixins are a huge win for React and not having them in 0.13 is holding me at 0.12 until they figure it out or revert...

      [–]danman_d 0 ポイント1 ポイント  (0子コメント)

      You probably know this already, but just to be clear - 0.13 still supports mixins if you use React.createClass - they just don't work if you declare your components as ES6 classes.

      [–]diamondnipples 0 ポイント1 ポイント  (0子コメント)

      Luckily, if you want to keep using mixins, you can just keep using React.createClass.

      Mixins aren't going anywhere for now.

      [–]diamondnipples 0 ポイント1 ポイント  (0子コメント)

      stupid JSX/react style attribute names, because of camelCasing fashion freaks

      You do realize that browsers use camelCase when working with style attributes, right?

      document.getElementById('#element').style.backgroundColor = 'blue';
      

      [–]more_exercise 11 ポイント12 ポイント  (6子コメント)

      I'm only partially aware of React.js, but at least these points that you have here don't seem especially strong.

      HTML directly mixed in your JS

      Do you use JQuery? Because $("<your html here>") seems to be just as liable to mix the presentation layer in with logic and break separation of concerns.

      .JSX files

      You don't run any post-coding steps on your coded JS files? Not even minification?

      [–]Ncksllvn[S] 3 ポイント4 ポイント  (5子コメント)

      I can't stand obscure selectors and mangled jQuery logic floating around - that's pretty much what conceived every modern UI framework. I'm comparing React to other UI frameworks, not stand-alone jQuery.

      I do use minification, but certainly not in development.

      [–]jarail 4 ポイント5 ポイント  (1子コメント)

      Give the 6to5 project a look. It supports JSX syntax. A lot of people are incorporating 6to5 (+webpack) into their workflows since the combination brings so much to the table. Regardless of if you want to use React, getting access to the new ES6 standard is a pretty big win.

      [–]Ncksllvn[S] 3 ポイント4 ポイント  (0子コメント)

      Just heard about that project today, but had no idea it supported JSX. That's pretty cool, and it also serves as testament to how much traction React has built.

      [–]danman_d 1 ポイント2 ポイント  (0子コメント)

      React gets a bad rap for this but every framework mixes presentation and logic in one way or another. In Angular, Backbone and Ember, you're generally pulling in a template that lives elsewhere even though there is a 1-1 relationship between views and templates (I'd call this indirection). And inside the templates, there are loops, type checks, etc. - ie. code! People seem to be so set on there being a hard difference between "presentation" and "logic" but every app contains at least some presentational logic (eg. if x == y display it this way, else display it another way).

      [–]nschubach 4 ポイント5 ポイント  (0子コメント)

      But something like Angular templates puts JavaScript like syntax in the HTML. (Loops, etc...). Actually, a lot of the various template engines seem to go out of their way to figure out how to write their own languages or dreadingly simplify JavaScript to the point where it's wholly unusable for anything but what the designers conceptualize you should be doing. You have a powerful scripting language and your are eschewing it for "Bob's Grand Script".

      [–]BosolaI still like Knockout.js 0 ポイント1 ポイント  (0子コメント)

      It doesn't matter how 'clear' your selectors are, you're still introducing coupling. And because you've "separated your concerns", that coupling is now invisible and impossible to reason about without looking at multiple files in advance or doing a build and seeing if anything breaks. Invisible, tight coupling. This is not an advance.

      Too many times have I had to deal with a project full of obscure empty divs, waiting to be used by some random script, possibly ported in from common code rather than the project itself, in some impossible-to-fathom manner. Anyone who tells you this achieves 'separation of concerns' and 'convenience of development' is wrong. Dead wrong.

      [–]jacobp100 8 ポイント9 ポイント  (23子コメント)

      I was sceptical about putting HTML in js too. But the fact is that as your application gets more advanced, with traditional frameworks, you have so much code in the HTML anyway. Also, JSX is optional. Use the native functions if you really want. It looks to be gaining traction now because of react native.

      [–]leptons 3 ポイント4 ポイント  (22子コメント)

      Tell that to all the designers I work with who don't know JS but who can style the hell out of HTML+CSS. I love it because I don't have to worry about the HTML/CSS at all - I hand off a basic html template file and they go to work while I make sure the platform JS code is solid (using angular). It's a real-world benefit that is erased with React having html inside the javascript. Programmers don't often do layout very well, and having to develop the React way is limiting who you can hire, and limits the scalability of a team.

      [–]agmcleodMelonJS Core @agmcleod 3 ポイント4 ポイント  (0子コメント)

      It's really not that much different from other templating languages. It has different syntax to learn and so forth. But I do agree it is a barrier to entry, and partly why i haven't used it at work yet.

      [–]danneu 5 ポイント6 ポイント  (19子コメント)

      Have you tried giving your designers more credit?

      Our designers edit our React code. They had to learn a few idiosyncrasies though like everyone has to for everything. Welcome to life and learning things.

      [–]leptons 0 ポイント1 ポイント  (18子コメント)

      So you like having more merge conflicts when a designer is working on the same javascript file as you? People singing praises of React aren't considering the real costs of adopting it, they only seem to be interested in their own little bubble. It's a very short-sighted way of vetting a technology.

      There are all kinds of organizations with all sorts of roles, and React seems to fit the best in teams of 1 developer, or teams of only JS devs. It simply isn't workable in many types of organizations.

      [–]floydophone 6 ポイント7 ポイント  (13子コメント)

      You're just moving the merge conflicts out of source control and into runtime, which is a much worse place to resolve them.

      I've now built big and small React apps myself, in a small startup and at a huge company. The only places they don't work out are where engineers are afraid to get the designers to change their process.

      [–]leptons -1 ポイント0 ポイント  (12子コメント)

      You're just moving the merge conflicts out of source control and into runtime

      I'm not really sure what you mean by this, it doesn't make any sense at all.

      If two or more people work on the same file, and check-in their changes, you will often end up with a merge conflict.

      You seem to really like jumping through hoops, but not everyone does. Adding complexity isn't a good thing. KISS is not just an acronym, it actually means something useful. Unfortunately, too many devs equate complexity with progress, but that doesn't work so well in practice. React needlessly complicates things by having HTML in the Javascript.

      It's also really disturbing that so many people are trying to redefine what "separation of concerns" means, and has meant for quite some time - if only to justify their decision to use React. It's really some cognitive dissonance going on with devs these days.

      Just because you can, doesn't mean you should - and that sentiment fits React like a glove.

      [–]floydophone 7 ポイント8 ポイント  (11子コメント)

      It does make sense, you just need to zoom out a little bit.

      A conflict means you need to reconcile two sets of changes to make a correct program. This can happen in git (i.e. you and I edited the same line of code) or it can happen at runtime (i.e. you changed the contract of a module I use and now my code is broken). One is alerted at merge time, the other is a runtime bug.

      For example, if you're doing classic jQuery + templates, a designer could change the class name of some element and break your JS. Even though they're in separate files, they're still intertwined together and I'd argue that this is just as much of a merge conflict as one highlighted by git.

      By colocating related code together, you decrease coupling and increase cohesion (you don't have two modules implicitly tied together and the combined file still only does one thing). These are generally good things.

      An example of "needless complication" isn't "the code doesn't look the way I'm used to it looking", it's "changes in module X affect changes in module Y and I don't know why". Modern web dev's version of separation of concerns encourages these types of architectures for no reason other than "it's the way it's supposed to be done".

      I actually think calling this "modern web dev" it is incorrect since it's clear that eschewing templates in favor of components has become accepted best practice in many circles (and growing).

      We are redefining "separation of concerns" as "modern" frontend devs use it because it's been used incorrectly for 10+ years.

      [–]leptons 0 ポイント1 ポイント  (9子コメント)

      You certainly like doing mental gymnastics to justify a bad design choices. Wait, I'm wrong, everyone in this thread cheering for React is just as confused as you are.

      "it's the way it's supposed to be done"

      This statement is just so wrong. You really think this is the way it is "supposed to be done" and every other way is not the way it's supposed to be done? You're just fooling yourself. Your statements are those of someone who drank the koolaid and is too far gone to recognize the shit they are slinging.

      [–]floydophone 0 ポイント1 ポイント  (8子コメント)

      I don't think you actually read what I wrote, but ok. My unsolicited advice is to keep an open mind because the world is changing.

      [–]leptons -4 ポイント-3 ポイント  (7子コメント)

      I did read what you wrote, and it's full of shit. You see things the way you want to, if only to justify your choice of framework. It's quite obvious if you "zoom out a little bit" that you aren't making much sense.

      [–]nschubach -1 ポイント0 ポイント  (0子コメント)

      I'd even argue that merge conflicts would be rare since you are working with such a small part of the page. In traditional template + code configuration you have a bigger chance that two (or more) people would be working on the same template at the same time.

      [–]gaearon 2 ポイント3 ポイント  (2子コメント)

      Well, you're wrong. Ever since we adopted JSX and React, our designer has been able to do much MORE. He now refactors components, creates new components, even tweaks some basic JS like rendering conditions. He couldn't do any of that with "traditional" template views.

      React is superior for designers for three reasons:

      1. Everything is a component. It's easy to create and compose components, and reuse existing component without understanding some aspects of how they are implemented.

      2. Designer can work with all states, not just initial one. React lets you describe DOM structure for any combination of data and state.

      3. Designer doesn't need to learn any fancy DSL a la ng-repeat and consult the docs all the time.

      Before making assumptions that something doesn't work, you might as well try it, can't you? Otherwise you're just spreading disinformation.

      [–]leptons -1 ポイント0 ポイント  (1子コメント)

      Before making assumptions that something doesn't work, you might as well try it, can't you? Otherwise you're just spreading disinformation.

      The same could be said to you.

      Everything is a component. It's easy to create and compose components, and reuse existing component without understanding some aspects of how they are implemented.

      Angular does this with no problems and without HTML inside Javascript.

      Designer can work with all states, not just initial one. React lets you describe DOM structure for any combination of data and state.

      Angular does this with no problems and without HTML inside Javascript.

      Designer doesn't need to learn any fancy DSL a la ng-repeat and consult the docs all the time.

      Angular does this with no problems and without HTML inside Javascript.

      [–]danman_d -1 ポイント0 ポイント  (0子コメント)

      The same could be said to you.

      How?! gaearon is an experienced dev who has tried many frameworks and uses React because he's found it works better than what he's used before (I know this because I've seen his posts and his code before). Why are you assuming it's his first time around the block?

      [–]html6dev -1 ポイント0 ポイント  (0子コメント)

      Oh you mean small teams like those working on Facebook products and instagram :p consider that maybe your designers and processes are the issue.

      [–]html6dev -1 ポイント0 ポイント  (0子コメント)

      From another perspective. It's all components, so designers have to add classes in fewer places, are forced to use best practices rather than just creating a new button and class set because the padding is slightly different on the new one (a major problem with designers for the very reasons you mentioned). With react className and style are just props so your designer can style <YourComponent /> just like a div if you keep this in mind. More importantly, before this we had templates languages on the server designers had to style or client templates they had to style. What are these designers going to do about Web components if this is such a problem??? This whole idea that designers only styling html is a factor is pretty far fetched. Finally, in my experience it's all a falacy anyway. You get designers who can code somewhat, or designers that can only make pictures in photoshop. If there are really designers out there that can only style html and aren't able to open a js file and find the tags we've got far bigger issues.

      [–]dsk 3 ポイント4 ポイント  (0子コメント)

      HTML directly mixed in your JS mixes the presentation layer with your logic, breaking separation of concerns.

      React IS your view layer, so it should have deep knowledge of your HTML structure.

      .JSX files - It's built around the concept of compiling your JS files, which to me seems like a framework overstepping its bounds.

      Why? JSX is syntactic sugar. You don't have to use it, but you should, because there isn't any good reason not to.

      [–]TheAceOfHearts 7 ポイント8 ポイント  (0子コメント)

      React is one of those things that looks like a terrible idea until you try it, and then you realize it's amazing.

      I had the same opinion but then I tried it.

      [–]BigOnLogn 7 ポイント8 ポイント  (0子コメント)

      1.) Turns out, "separation of concerns" isn't that great. See these talks by Pete Hunt and Tom Occhino for Facebook's reasoning. Or, just Google "reactjs separation of concerns." It's been discussed ad nauseum. The gist being, the benefits of separation of concerns aren't as good as the benefits of developing in a component-based architecture (which is what react/jsx gives you). Side note: you don't have to use jsx.

      2.) Compilation is a non-issue, IMHO. Chances are, in any project of size, there already a compilation step.

      My suggestion, give react a try over a weekend. I'd bet the benefits of components will ease the heartbreak of having to compile code and above you of the sin of not separating your concerns.

      [–]angus_the_red 4 ポイント5 ポイント  (4子コメント)

      I just started using it a month or so ago. I love it.

      1. Declarative code is super easy to reason about.

      2. One way data flows are easy to follow.

      3. Components, composition, co-location. Having view behavior and style and markup in the same file is amazing.

      4. It allowed me to give a middle finger to CSS. It's all about inline styles.

      React.js isn't the final view framework, but it is a huge improvement. Check out some of the videos from the recent conference if your curious.

      [–]benjp2k1 0 ポイント1 ポイント  (3子コメント)

      Might I ask what tutorials etc you may have used/still use? I've picked it up for a side project but keep hitting walls and find there still to be a lack of decent information.

      [–]angus_the_red 0 ポイント1 ポイント  (2子コメント)

      The docs at github for reference and a lot of trial and error. The project isn't mature yet, so it's a slog to her started.

      There are several boilerplate projects on github and npm that would probably help you get started.

      I'm writing a hybrid mobile app so I went with react-flux on npm. It was a huge help, but I've refactored it heavily since then. If you aren't writing a mobile app, it's probably not the right choice for you.

      Good luck!

      [–]benjp2k1 0 ポイント1 ポイント  (1子コメント)

      Project I've been building I've used things like:

      • react-google-maps
      • react-googlemaps

      only to find that one works much differently than the other (and stuck with react-googlemaps).

      • firebase
      • geofire

      only to find that even with geofire I can't do queries against multiple criteria (such as geo bounds of a map). I'm now trying to look at mongo options.

      haven't even started to use flux yet... but it looks like another incoming headache.

      My end result is supposed to be a responsive webapp that I will eventually use cordova or similar to look at flipping to mobile apps.

      [–]angus_the_red 0 ポイント1 ポイント  (0子コメント)

      Flux isn't hard. It does take discipline because it's indirect and an extra bit of boilerplate code.

      Relay may simplify that a bit when it is released.

      [–]lonahex 4 ポイント5 ポイント  (0子コメント)

      1. HTML directly mixed in your JS mixes the presentation layer with your logic, breaking separation of concerns.

      This is the biggest misconception among people reading about react. You don't have to store logic in your components. In fact, it is not even recommended. Only pieces JS code that goes into your components are, triggers and UI behaviour. For example, if my component is a button, I should write the code to change it's appearance in the controller, not to submit an ajax request. I can tell some other part of the application to do that for me (Actions) and then do data manipulations in yet another part (Stores).

      React (+ Flux) actually does a great job at separating concerns. Read about flux. If you want to try it, give reflux.js a shot. It is a slightly impure but simpler version of the flux architecture.

      Example: Lets say you have a "like" button. When clicked, it send a POST request to the server to record a like and it also changes it appearance. A very basic (perhaps non-working) example would look something like this,

      var Like = React.createClass({
          like: function(){
              this.setState({liked: true});
              Actions.like();
          },
          unlike: function(){
              this.setState({liked: false});
              Actions.unlike()
          },
          render: function(){
              if (this.state.liked) {
                  return <button onClick={this.unlike}>Unlike</button>
              } else {
                  return <button onClick={this.like}>Like</button>
              }
          }
      });
      

      This component only declares what the UI should look like and hands off the "logic" part to Actions. A real world like button would look much different. You'd probably use state to update in real time but overwrite it with props, or you would split the action into 2 (requestLike/Unlike and Like/Unline) and only use props to store status of the button. Also there would be IDs involved, etc, etc.

      If you are inclined enough, your logic doesn't even have to be a reactjs thing. It can be plain old JS functions, backbone collections/models/controllers or whatever.

      In my opinion React actually properly separates the concerns.

      Actions -> Logic, Network stuff, etc.

      Stores -> Your data and operations you want to perform on it.

      Components -> Just the UI.

      I've left out a big part of the flux philosophy, the one-directional data flow. This makes the whole thing work so beautifully and tames even the most complex beasts of interfaces. Read about it.

      [–]achen2345 2 ポイント3 ポイント  (3子コメント)

      What makes React very popular:

      • XML pieced into the JS for templating. Web newbs tend to HATE XML, but old timers love it. XML is too verbose for data serialization, but it is absolutely fabulous for higher order concerns like semantics, language, context, and such. JSON is basically the opposite.
      • React attempts to address the same templating/framework problems that all the MVC frameworks attempt to solve, but it is not MVC. MVC is extremely OOP, which I guess is cool if you would rather be writing Java or Python or anything else.

      Separation of concerns is wildly misunderstood. It is about separating requirements into their own respective quasi-isolated realms. It is not about separating code syntaxes that look different. MVC fails at this where there is a separation of model, view, and controller that represent a single component. It still intermangles behavior, content, and presentation. It is more clear to put all the templating logic together in a single bundle (a single concern) and separate out presentation and behavior.

      [–]mnokeefe 1 ポイント2 ポイント  (2子コメント)

      React does fit in to the MVC pattern, it's designed to be the view and only the view. This is taken directly from the React homepage:

      "Lots of people use React as the V in MVC. Since React makes no assumptions about the rest of your technology stack, it's easy to try it out on a small feature in an existing project."

      [–]gaearon 2 ポイント3 ポイント  (0子コメント)

      That's how they chose to sell it (can't fight all battles at once), but you will find that top-level views often fill the role of Controllers. And you don't need Models because you have JS objects and arrays.

      [–]nschubach 0 ポイント1 ポイント  (0子コメント)

      It fills the View and the Controller. In fact, it basically takes the standard V/C paradigms and makes the Dev create hundreds of little V/C combinations instead of trying to make large monolithic controllers to manage forms. In React you manage fields.

      [–]evereal 1 ポイント2 ポイント  (0子コメント)

      HTML directly mixed in your JS mixes the presentation layer with your logic, breaking separation of concerns.

      Separation of concerns should not mean arbitrarily separating the various web technologies. React actually encourages the good kind of separation of concerns by recommending things like Flux, where you would separate your business logic from your view logic for example.

      The reality of today's webapps, is that your components will often have view logic which is as much a part of it's view as any other <div> or <input> in there. Quite simply, your component's HTML is completely broken without that logic, and that logic is completely specific that that particular piece of HTML. It makes no sense to forcefully separate those things, both of their concerns is exactly the same, they just happen to be using two different languages.

      [–]vittore29 1 ポイント2 ポイント  (1子コメント)

      A little bit off-topic, but does anyone have a link to more sophisticated example of flux/react, meaning data entry of more than one field per entity and ideally tree-like structure? All those examples showing something like

         <input name="search-value" onChange={@onChange} /> 
      

      or in best case

         <input  type="text" valueLink={this.linkState('newDescriptionText')} />
      

      which is not clear how to use with flux or in case of state.a.b.c fields to bind

      [–]siegfryd 0 ポイント1 ポイント  (0子コメント)

      It'd be mostly the same as how you'd do it with state, except instead of calling setState you're using an action creator and creating an update action. If you have a nested object you could either have individual actions for every little bit of the form, or just have one big update form action that takes the modified form object.

      [–]sazzer 0 ポイント1 ポイント  (0子コメント)

      Both of those can be avoided. You can write your code purely in Javascript and totally ignore JSX, and it will work perfectly fine. You are still defining your markup in the Javascript, but it's not embedded HTML...

      As for the combination of presentation and logic, if you use something like Flux alongside it then all the presentation layer is doing is rendering to the screen and triggering actions, and the resolution of those actions is what does the actual logic. This means that the same action can be triggered from all over the place and it all does the same thing - which it should.

      [–]serapath 0 ポイント1 ポイント  (0子コメント)

      Maybe this is a stupid question, but: If a user interaction changes a model and i have a mechanism to listen to those changes in order to update the components in the view, where each view does not just re-render it's template, but updates very TARGETED only that part of it's template already in the DOM, that needs changes... ... and i use "requestAnimationFrame" + intelligent batching of read's and write's (by using something like https://github.com/wilsonpage/fastdom)

      wouldnt that be faster? (because i do not need to compute a diff)

      [–]fooey 0 ポイント1 ポイント  (0子コメント)

      Facebook making it was actually a big turnoff for me orginally

      I'd say React is popular in spite of FB, not because of FB

      [–]Uknight 0 ポイント1 ポイント  (0子コメント)

      Have you given it 5 minutes yet?

      [–]MashedPotatoBiscuits 0 ポイント1 ポイント  (0子コメント)

      I hated it too before i started using.

      [–]TheTophs 0 ポイント1 ポイント  (0子コメント)

      I find it appealing for a few reasons, but a couple big ones are:

      1. You described the markup in JS as breaking separation of concerns, but I actually find it appealing. You can use React as a pure view. In that use case, I see it as appealing to have markup and styles all in one place. I like using inline styles with JS a lot more than using CSS because it reduces some headaches from unexpected CSS quirks breaking your styles.

      2. The real benefit I like is that the model React uses involves all components just rendering based on state and props. You can not worry about your views being in sync with your model because you just pass down props and state to child components and everything will re-render correctly and in an efficient way. It really can help clean up some code that could otherwise be very tangled and difficult to manage when adding new features.

      Regarding JSX, it would be nice to not have to convert to JS files, but I tend to use browserify anyways, so it doesn't complicate that workflow. However, you can avoid JSX altogether if you want to. I just prefer the JSX syntax because the markup looks similar to a DOM hierarchy.

      [–]RandolphoSoftware Architect -5 ポイント-4 ポイント  (4子コメント)

      React is everything that was ever wrong with PHP shuffled off to the browser.

      [–]myalternatelife 3 ポイント4 ポイント  (3子コメント)

      Wha-what? Can you elaborate on this?

      [–]Punting 5 ポイント6 ポイント  (1子コメント)

      He's a "Software Architect". He doesn't need to elaborate.

      [–]RandolphoSoftware Architect 1 ポイント2 ポイント  (0子コメント)

      Yes, I just live in my ivory tower throwing documents at typists developers. :)

      [–]RandolphoSoftware Architect 0 ポイント1 ポイント  (0子コメント)

      Basically, the first thing OP complained about is first thing people who grew out of being a junior developer complained about with PHP.

      [–]koglerjsIt's 'Javascript' - 'JavaScript' looks funny | koglerjs.com -1 ポイント0 ポイント  (0子コメント)

      I am in strong agreement when it comes to JSX, but React is popular because when it came out it was a truly new idea about interacting with the DOM, something that no one else was trying and something demonstrably better.

      It is certainly not popular only because Facebook made it.

      [–]mooogs -3 ポイント-2 ポイント  (0子コメント)

      "What's so great about React.js?"

      read the homepage.

      [–]killinghurts -4 ポイント-3 ポイント  (1子コメント)

      I agree I think point 1 kills it for me.

      RequireJS + !text plugin is the bet I've come across so far.

      [–]killinghurts 0 ポイント1 ポイント  (0子コメント)

      Ooee plenty of Angular fan-boy downvotes around here.