66 points · by s3nnyy · 11y ago · 37 comments
Flux on the other hand was hard to grasp, since all of the different implementations and the naming problems. Actions in MVC are just methods of the controller classes, but in Flux they are objects, which kinda threw me off track right in the beginning.
Also, I came from ExtJS and Ember and was accustomed to two-way data binding and the whole Flux thing felt backwards, because interacting with the Models in Ember-Data didn't take any effort. After they were bound I just needed to type my data and they get updated automatically. I just had to look about gathering them at the end and send their updates to the server.
I was always confused with 'Flux' and was never able to understand it. Redux is very nice.
But I didn't choose it. Another dev at the current project did.
It took me a few weeks to fully understand what Redux is about. I didn't know about "one store for all", the difference between actions and action creators and how immutability was mandatory.
I just jumped in and started my first component with a (rather bad) tutorial I found with google and copied a Redux store and actions from a co-worker.
The Redux docs weren't good till 1.0
After I asked Dan something I realized I got it all wrong. But now I think it's a really nice way to do front-ends.
$.post('/login', credentials, function(user) {
$('header.name').text(user.name);
});
> I can tell you from experience that this code will ruin your lifeThe alternative isn't React. It's
$.post('/login', credentials, function( user ) {
setUserName(user.name);
});
// Somewhere else...
function setUserName(name) {
$('header.name').text(name);
}
React doesn't tell you 'who changed the header' either. Other than having a central point through which changes are routed: like a function.React gives you incremental HTML rendering via a virtual DOM. Which saves you having to do that manually (though in many cases you don't need to do it at all). A lot of this article reads like framework-fetishism.
On Flux, I like his comments there. I'm thinking of reinventing the command pattern in Javascript and calling it SuperFlux...
This approach punts the ball into part of the field you can see, understand and control. React punts the ball into someone else's stadium.
Framework-fetishism is being enamoured by things a framework does that you could do yourself in a couple of lines of code. Unfortunately Javascript programmers seem to be very vulnerable to it. There are good reasons to use React, but they aren't what the article wants to praise.
I'd much rather punt the ball into a stadium with some properties/parameters than run the logistics of a game myself (security, ticket sales, refereeing, etc). It's saved me gobs of time as a developer. Again YMMV.
> React gives you a template language and some function hooks to essentially render HTML.
This is actually wrong, despite the official page saying the same. It's the biggest misconception in the React community. render() function outputs a data structure which describes HTML and ALSO user event handlers on that HTML. Any UI program does both: handle input user events and generate graphics output. A View is only the latter part, hence React cannot be only the View.
Refer to original MVC paper http://heim.ifi.uio.no/~trygver/1979/mvc-2/1979-12-MVC.pdf
> A view is a (visual) representation of its model.
> … a view should never know about user input, such as mouse operations and keystrokes.
1: it's not that big a deal if you choose the "wrong" one. Flux implementations are small and based on many similar concepts. Even if you choose one that ends up being unmaintained, your flux choice will still stay a solid choice. We are using 3 different flux implementations in our apps, and have no plans to migrate any of them.
2: It's starting to look like redux has "won". Flummox, which was previously a leading contender for the title, now recommends redux. Redux has a very simple core, is an excellent merger of the best concepts of flux, elm and others, has great documentation, and an extensive ecosystem of plugins.
I just wished Redux was a bit more opinionated. But it not being so will certainly please many other people.
We use React since four months, and we develop faster compared to before, when we used only jQuery.
(Genuine questions, not making a point).
I think there are many reasons for the productivity boost. Thinking in components, more readable code, great debugging possibilities, understandable data flow, to name a few.
And, last but not least, it is lots of fun :-).
Soundcloud might be "slower" than StackOverflow because it continuously streams music while you're navigating the page. A car is also slower than a drag racer, because it fits multiple people, luggage, and conforms to several safety standards. But maybe we should all be driving drag racers instead.
I've been doing React for a few months now. I definitely like it better than Ember/Handlebars, Angular or vanilla jQuery for managing views. It's much easier to reason out what your view looks like and how it can change.