Live data from Hacker News

React: Finally, a great server/client web stack

eflorenzano.com

21–30 of 134 posts

Re: React: Finally, a great server/client web stack

#21

If you used this with Backbone, could you throw Backbone's entire View object away and use this instead?

Yes, that's the approach I took in our Marathon project (https://github.com/mesosphere/marathon/tree/master/src/main/...). The view is React, the models are Backbone, and I intend to use Backbone's Router as well. Backbone.View is never used.

Re: React: Finally, a great server/client web stack

#22

> You can choose to use this, but after getting over my initial distaste for it ("Ack! Who got markup in my code!"), I could never go back to not using it. Or you could just use HTMLbars/Handlebars. Seems like "JSX" is just a more complicated version of a Mustache-esque logic-less template.

The big difference is that Handlebars always produces strings that your browser has to parse as HTML. Handlebars also doesn't know how to mutate between states, meaning if you add a class 10 levels deep in the template the best you can do is re-render the entire thing.

JSX + React produce functions that return React's representation of the DOM, their "virtual DOM", and React knows how to make small mutations based on state. If a change in state only needs to add a class 10 levels deep in the hierarchy, that is the only change that happens in the real DOM; it doesn't have to re-render the entire template.

Re: React: Finally, a great server/client web stack

#23

If you used this with Backbone, could you throw Backbone's entire View object away and use this instead?

Yes, and that's a great use case for it.

But you can also use your existing Backbone Views (if they have some nice, say, formatting or data-munging-for-display logic in them) and simply replace your render function with React.

The next step you can take is replacing your HTML templates with React's JSX templates, if you'd like...

Re: React: Finally, a great server/client web stack

#24

> You can choose to use this, but after getting over my initial distaste for it ("Ack! Who got markup in my code!"), I could never go back to not using it. Or you could just use HTMLbars/Handlebars. Seems like "JSX" is just a more complicated version of a Mustache-esque logic-less template.

I've gotta agree with the author on this one. Upon first glance at the example code, JSX looked really ugly and unnecessary. As I started to use it, I really came to appreciate it in the context of React. JSX syntax allows you to do React-y things, like call child components and pass in props, in a very concise way.

Re: React: Finally, a great server/client web stack

#25

If you used this with Backbone, could you throw Backbone's entire View object away and use this instead?

Yes, and that's a great use case for it. But you can also use your existing Backbone Views (if they have some nice, say, formatting or data-munging-for-display logic in them) and simply replace your render function with React. The next step you can take is replacing your HTML templates with React's JSX templates, if you'd like...

Thanks for replying and for your work on CoffeeScript and Backbone. I might give this a try as I love Backbone's Model layer. I think I like the second approach you suggested better. That might almost turn the Backbone.Views into ViewModels, right?

I'm still up in the air on how I feel about the whole JSX thing but I'm willing to give it a try.

Re: React: Finally, a great server/client web stack

#26
Am I the only one that kind of thinks most websites should just be static pages? Like, I get pretty irritated when I go to read a blog post on Medium or wherever and it loads a header and a blank page, and then loads a bunch of javascript (mostly tracking and analytics frameworks), and finally goes out and gets the actual content. And then if I scroll down, it has to load some more garbage from Disqus or something.

PLEASE JUST GIVE ME A STATIC PAGE WITH YOUR CONTENT.

I really do not care if the comments don't refresh live.

Re: React: Finally, a great server/client web stack

#27
post #12

Earlier quoted context omitted.

JSX isn't markup - it's XML which translates to Reacts internal representation which looks something like: bar --> React.DOM.div({ className: 'foo', children: 'bar' }) You don't have to use it - it's a convenience provided for designers (and arguably developers who have realised that templating provides a false separation of concerns). Om notably ( https://github.com/swannodette/om ) ignores it.

"JSX isn't markup - it's [Extensible Markup Language]"?

JSX isn't markup, it's a compiler that transforms common HTML-like to custom React.DOM objects. From the doc [0]:

> JSX transforms from an XML-like syntax into native JavaScript.

[0] http://facebook.github.io/react/docs/jsx-in-depth.html

Re: React: Finally, a great server/client web stack

#29

Am I the only one that kind of thinks most websites should just be static pages? Like, I get pretty irritated when I go to read a blog post on Medium or wherever and it loads a header and a blank page, and then loads a bunch of javascript (mostly tracking and analytics frameworks), and finally goes out and gets the actual content. And then if I scroll down, it has to load some more garbage from Disqus or something. P…

Statistically speaking, yes, you are the only one.
Post reply on HN