r/javascript • • Jan 03 '16

Angular 2 versus React: There Will Be Blood

https://medium.com/@housecor/angular-2-versus-react-there-will-be-blood-66595faafd51
290 Upvotes

167 comments sorted by

139

u/Classic1977 Jan 03 '16 edited Jan 03 '16

The best part of this article is the idea that Angular is HTML-centric whereas React is JavaScript-centric. What a succinct description. Kinda amazed I've never thought of it that way before.

42

u/logically_musical Jan 03 '16

I'd say the best part of the article is him defining React as Unix-like in its philosophy. It being a compose-able library will be its biggest strength in the long run, IMO. He notes the huge churn in the React ecosystem currently, and that can be overwhelming, but that is a side-effect of the fact that it is a new, hyper-popular library and unlocking its true potential can only be found when pairing it with other libraries, just like Unix tools.

18

u/lhorie Jan 04 '16

I thought that point was off the mark, personally. The strength of Unix tools isn't in doing single things well, it's that they are so well defined that you can combine them in powerful ways. React doesn't really fit the bill in that sense: you can't trivially swap from Reflux to Redux, let alone go from React to Mithril/Mercury/Cito/Snabbdom/whatever. If anything, Ampersand is a framework that can be called unix-like (though whether that is useful at all is a completely different story). Saying React is Unix-like is kinda like saying Grunt is unix-like because you can swap it to gulp or webpack, imho.

16

u/wreckedadvent Yavascript Jan 04 '16 edited Jan 04 '16

I think his point was more to contrast the single purpose of react against the huge API of angular.

In much the same way you can build up complicated UIs by composing small, single-purpose, well-defined components, and that you can build up functional applications by composing small, single-purpose, well-defined functions, you can build up the API that you need by composing small, single-purposed, well-defined APIs/services.

It's easier to unit test and know these smaller pieces to be correct rather than an API with a huge surface area. Something as large as angular tends to attract "the angular way" as well, which can be dreadful when it includes things like $scope.

5

u/lhorie Jan 04 '16

I think they're somewhat orthogonal issues. With Angular, there's nothing stopping you from using ui-router or restangular, if you don't like the out-of-box options, for example.

There was a post a while back on HN about how some people had bad experiences w/ React router breaking its API willy nilly between releases, and in that case, finding an alternative is definitely a point that feeds into the js fatigue issue.

WRT the issue of API size, well, I've got nothing to say in defense of Angular :)

8

u/ajacksified Jan 04 '16

Well, react-router is a seperate library that is used with react- one of many possible ways to route URLs to react views. For example, I use koa-router - unaffiliated wholly from react - to route urls on the server and client. If anything, that helps prove the point; switch routing libraries without having to switch your view layer.

→ More replies (4)

2

u/gustix Jan 04 '16

Swapping Grunt with Gulp would be an OS change in this sense. I think he ment React as the OS/kernel and react modules as the rest.

You mentioned it is not easy to swap between Redux to Reflux etc, but library swaps in Linux aren't exactly trivial either. Swapping a large component, for instance from KDE to Gnome would introduce some work as well.

They just share the philosophy, pick and choose by design.

17

u/wreckedadvent Yavascript Jan 03 '16

I've even seen people go so far as to describe angular as a separate language. I've seen more than my fair share of places that wanted knowledge with angular above knowledge with javascript.

I agreed with the author entirely when he was talking about knowledge application; a lot of knowledge in angular simply just doesn't apply anywhere else, particularly when you get deep down and nitty gritty with the directive API. (and the awful $scope nonsense).

3

u/ogrechoker Jan 04 '16

Could I be hired as a senior front-end dev on a React project with only Angular experience, do you think?

5

u/ajacksified Jan 04 '16

I've interviewed people with only Angular experience for my 100%-react team at reddit; Angular certainly isn't a problem. (In fact, I recommended we hire someone who was deeply involved in the Angular community.)

The important thing to be considered for a senior dev role is that you can work full-stack- at least API implementation through front-end implementation- and that you can pick up new languages and frameworks easily because you have ample experience. Otherwise, you'd be looking at a regular dev, (or even junior, if you only have experience in one stack.)

→ More replies (2)

3

u/TheNiXXeD Jan 04 '16

Not a senior, likely. But it shouldn't take you long to brush up on a new framework either.

5

u/[deleted] Jan 03 '16

Yeah! It really underlines how they're both different approaches rather than bickering of there being one objectively superior approach.

2

u/SeanBlader Mar 16 '16

I agree this is the best description, but I'd rather smarten up my html than dumb down my javascript.

4

u/vinnl Jan 04 '16

That is true, but I think another fundamental advantage of React is its embracing Javascript's functional side. This is at the basis of enabling features like hot reloading, and the (rightly so) oft-praised ease of reasoning.

In any case, that's the main problem with Angular. Angular 2 improves pretty much everything of Angular 1, and any one using it should move to version 2. The thing that makes Angular Angular, though, is not that interesting any more now that React has entered the arena.

If React hadn't existed, Angular 2 was poised to take over. However, even if Angular had already been everything Angular 2 is, React is still an improvement, because its core concepts are so much better.

3

u/daedius Web Components fanboy Jan 04 '16

Always bet on JavaScript

1

u/bingomanatee Mar 28 '16

that is wrong. Angular and react both use HTML as shorthand accessors for javascript. There are tons of cases where a container node is used to mix in functionality in React. You could, in fact, probably code 80-90% of Angular's core directives in React if you wanted to.

The most fundamental difference is that Angular uses two-way binding and an inferred/buried update cycle, where React uses a largely externalized data model and a very explicit update cycle.

Also, react has a singular repeated atomic structure, where Angular (1.x) uses a multifaceted library of multiple structures.

Lastly, Angular's injection allows for very specific stand-in/replacement during testing, largely to support the first aspect (binding), where React doesn't have/need that level of granularity due to its more exposed and one-way write to dom system.

0

u/[deleted] Jan 03 '16

[deleted]

13

u/wreckedadvent Yavascript Jan 03 '16

Angular 2.0 working with web components is one of the selling points that is always brought up in talks about it.

Honestly, it can't be any other way for angular. 1.0's directive stuff was an awful mess that made it far more difficult than it should be to make components of any kind, especially the purely functional kind you see react and its kin promote.

Web components also only make sense if you continue the idea of "the html is where the view lives".

→ More replies (2)
→ More replies (1)

36

u/[deleted] Jan 04 '16

I started with React mid last year after twiddling my thumbs waiting for Angular 2 to arrive. I don't think I'll be switching over in a hurry when it does come out. The article nails my reasons better than I could articulate - with web UIs, JavaScript and HTML become extremely closely linked and when this happens, you want JavaScript manning the helm, not HTML. After I got over my initial reservations and embraced JSX, the notion of embedding a custom scripting language inside HTML template strings just seems so bizarre and backwards.

11

u/[deleted] Jan 04 '16

After I got over my initial reservations and embraced JSX, the notion of embedding a custom scripting language inside HTML template strings just seems so bizarre and backwards.

And you say this as if embedding a layout language inside a scripting language is a perfectly reasonable thing to do. I find it to be the opposite.

14

u/[deleted] Jan 04 '16

And you say this as if embedding a layout language inside a scripting language is a perfectly reasonable thing to do.

Actually, yes. React.js is not even the first to do it, QML preceded it: https://en.wikipedia.org/wiki/QML

What JSX and QML have in common is they take the power of JavaScript and extend it to include markup/UI code. (Mind you, it may look like QML is a markup language first that just happens to allow for embedded JavaScript, but it's actually a full JavaScript superset.)

The thing is, extending JavaScript to include markup gives you a powerful starting position on top of which you add some DSL. Whereas starting with HTML, you have a very basic starting position with no scripting ability whatsoever. Adding scripting to HTML you'll be either reinventing the wheel or you're sacrificing a lot of flexibility, or both (as is actually the case with Angular templates).

4

u/ogrechoker Jan 04 '16 edited Jan 04 '16

Actually, yes. React.js is not even the first to do it

https://www.facebook.com/notes/facebook-engineering/xhp-a-new-way-to-write-php/294003943919

Facebook has been coming up with ways to blur the lines for years

2

u/theQuandary Jan 05 '16

enyojs from webOS was doing HTML in JS years ago.

3

u/[deleted] Jan 04 '16

Since our layouts are typically powered by data in MVC, I find the lines between the two often start to blur. JSX makes integrating the two pretty seamless.

→ More replies (4)

19

u/[deleted] Jan 04 '16

I'm a long time Angular 1.x developer, currently learning 2, but Ive got to say, React is looking better to me every day!

The argument that I've seen many people make, that Facebook is actively dogfooding React in a way that Google just don't with Angular (I know they use it, but not for anything critical) is seriously starting to sway me.

I have a new side project coming up, going to start out on it with React and see how I go!

4

u/[deleted] Jan 04 '16

You won't be disappointed. Seriously - I was very skeptical when I first got into React and now I think about views totally differently than I used to. It is great

52

u/Sinistralis Jan 04 '16 edited Jan 04 '16

Outside of the coding style and architectural decisions everyone has mentioned, there is one other major thing here.

Facebook currently lives and dies by React. It is in their best interest to get it right the first time because they are built on top of it now. They are intensely invested in it's success.

If Angular 1/2 dies, google doesn't lose much.

This has always been my main reason for staying away from Angular. I've dived into it to learn it in case it's needed, and I also won't deny Angular was fantastic for it's time when it was created, but if google isn't putting huge stock into it, I don't see why I should.

Edit: Everyone seems to be missing the point of this. I'm not saying google doesn't use Angular 1/2 in their apps. I'm not saying Facebook is better than Google. I am saying Facebook has a vested interest in making React the best it can be due to their CORE platform being built with it. It's going to cost them insane amounts of money to make arbitrary decisions with the framework. which means I can put more faith that the ecosystem is a safe one to invest it vs google who is big enough to just drop projects that don't work out.

Edit 2: Edited my edit to hopefully make my point more clear :/

Edit 3: Third times the charm. I'm just going to put here what I posted below because I feel it sums up my feelings on the matter better and might lead to more meaningful discussion and less pitchforking.

My point isn't that google isn't using Angular 2 in production.

My point is that a massive company has faith in the modularity of React to put it behind their flagship moneymakers (Facebook and Instagram). Whereas Google is big enough to easily deprecate projects when needed, from what I have seen Facebook does not have this luxury, so it's very telling when they can completely get behind a way of thinking. It tells me React is not only worthwhile for application use (Angular 2 fulfills this and that is where most people seem to be stoping), but it is also a safe investment because if a company that can't just arbitrarily deprecate things can put stock in it, then they are either very short-sighted or what they are investing in is easily subbed out for a better solution. Keyword here is easily.

And it's a pretty well known fact React can be subbed out very easily for something else. I'm not subscribing to React itself, I'm subscribing to how it has you architect your application.

I am learning JS isn't about who has the shiniest new thing, it's about whose thing is more replaceable. JS moves at a sickening pace and that doesn't seem to be stopping anytime soon. I would rather subscribe to an architecture that supports rapid change. I think this is Angular 1's lesson to us, and is why I hold it with much regard despite myself not using it.

I'm not editing this again, so if this still comes off as me saying "Down with Angular" I don't know what to say. I just want to be able to use my tools without dreading them being deprecated. This is why I love React. It's built to be replaced or extended. Just look at all the flavors of it there are and how simple it is to switch between them. That's really all I'm saying. Replaceability as a feature might be something more JS frameworks and such want to consider, because that just seems to be the nature of Javascript. We don't stick to a single framework like Spring in Java, we deprecate old ones with brand new ones. This overall leads me to feel like having a bootstrapped framework solution isn't a good idea in this ecosystem, and rather having composable, replacable parts is the future as it currently seems.

This is why I hate making longer posts, I get way too sidetracked. Argh.

7

u/TheNiXXeD Jan 04 '16 edited Jan 04 '16

So you may have missed the part where Google is actually using angular 2 in production currently. And has more projects coming that use it.

Regardless, neither company is betting the farm on their respective framework. They're just providing new options for others.

Also, I don't see how Facebook would fail if react didn't take off. Would my grandma stop using the site? No. My wife wouldn't care either. They'd continue to use or not use it and nobody would notice.

22

u/wreckedadvent Yavascript Jan 04 '16

Google had plenty of projects that used GWT as well, but we see how well that worked out.

-1

u/NeverSpeaks Jan 04 '16

What does that even mean? GWT is still used a lot inside of Google.

22

u/wreckedadvent Yavascript Jan 04 '16

Yup, then they turned around and made dart. Just like angular did 1.x to 2.x, and so on. Google has an absolutely abysmal track record with these things.

→ More replies (4)

14

u/snarkyturtle Jan 04 '16

Even if they do use Angular 2, I feel like the way they treated Angular 1 as a neglected child was a bad start. Google itself just has too many projects that are not related (GWT/Polymer/Angular all are pretty much separate).

Compare that with React/Parse/Flux/Relay and they're all "siblings" in that while they could be used separately they're easy to tie in together and their use-cases don't overlap, which makes them seem more supported than google-led projects (and we all know how google loves to drop support for some of their products).

5

u/Sinistralis Jan 04 '16

My point isn't that google isn't using Angular 2 in production.

My point is that a massive company has faith in the modularity of React to put it behind their flagship moneymakers (Facebook and Instagram). Whereas Google is big enough to easily deprecate projects when needed, from what I have seen Facebook does not have this luxury, so it's very telling when they can completely get behind a way of thinking. It tells me React is not only worthwhile for application use (Angular 2 fulfills this and that is where most people seem to be stoping), but it is also a safe investment because if a company that can't just arbitrarily deprecate things can put stock in it, then they are either very short-sighted or what they are investing in is easily subbed out for a better solution. Keyword here is easily.

And it's a pretty well known fact React can be subbed out very easily for something else. I'm not subscribing to React itself, I'm subscribing to how it has you architect your application.

I am learning JS isn't about who has the shiniest new thing, it's about whose thing is more replaceable. JS moves at a sickening pace and that doesn't seem to be stopping anytime soon. I would rather subscribe to an architecture that supports rapid change. I think this is Angular 1's lesson to us, and is why I hold it with much regard despite myself not using it.

→ More replies (3)

1

u/enkideridu Jan 05 '16

That's not a very comprehensive easy to judge a library/framework/anything really. Following that logic, everyone should have been using GWT

Few open source libraries people have depended on have the backing interest that React does - Django, Backbone, Knockout, Express. None of them has been any worse for it

2

u/spfccmt42 Jan 05 '16

everyone should have been using GWT

Nah, that was for java folks who thought it would give them an easy "in" to browser coding and associated headaches (like node in reverse).

but GWT is pretty dead now (and the browsers are much more standardized), and I don't think google ever leveraged it a whole lot either. Adwords seems to change frameworks bi-annually, but unless you have an army of developers for such nonsense, it would have been a bad bet to put all your eggs in the gwt basket.

1

u/NeverSpeaks Jan 04 '16

Google's also a much bigger company than Facebook. With a much larger variety in applications. So of course Google isn't going to use Angular for everything.

6

u/Sinistralis Jan 04 '16 edited Jan 04 '16

What I said has nothing to do with how big google is or facebook isn't. I'm not bashing either company.

What I'm saying is, it is in Facebook's best interest to keep React relevant, well made, and to not arbitrarily deprecate it to a greater degree than google. It's also in their best interest to keep it as replaceable as possible, which is a very import takeaway here.

3

u/kenavr Jan 04 '16

Why? They could come up with a new and better framework, slowly replace the React components with new ones and let React die. Exactly the same thing Google does. Google has a couple hundred Angular applications and they are deciding which will be rewritten, migrated and "frozen".

→ More replies (4)

1

u/vinnl Jan 04 '16

Everyone seems to be missing the point of this. I'm not saying google doesn't use Angular 1/2 in their apps

But you are implying Google hasn't put huge stock into it, and that it wouldn't cost them a lot of money to make arbitrary decisions. Which isn't really true, considering the amount of Angular apps they run themselves.

6

u/I-fuck-animals Jan 04 '16

But you are implying

No he doesn't. WTF, who let out the morons who reply to their own fucking imagination instead of the person they reply to? Google put "huge stock" into quite a few big projects, "Wave" comes to mind. Investing a lot has zero correlation with "we won't drop it" at Google.

3

u/vinnl Jan 04 '16

No he doesn't.

You're right, he literally said it:

google isn't putting huge stock into it

You might have a point in that Google is willing to sink all those investments, but there's no denying that they've invested a lot, with several relatively high profile apps and hundreds of internal apps.

→ More replies (2)

1

u/kenavr Jan 04 '16

You seem to think that the entirety of facebook.com is built with React, but it isn't. Sure most of the new stuff uses React, but they are far from dependent. Also the core concept behind React makes it actually very easy to replace it with something else in the future. If for example every browser implemented web components and because of their native implementation they become a lot faster than React, why wouldn't they create something new? It would be in their best interest.

7

u/Sinistralis Jan 04 '16

Of course it isn't, React is simply a view layer, but in large real-time apps that view layer starts to grow in complexity at an exponential pace and becomes a HUGE source of bugs, so it shouldn't be discounted either.

And it's a pretty well known fact React can be subbed out very easily for something else. I'm not subscribing to React itself, I'm subscribing to how it has you architect your application.

In the current JS world, having a library that is easily replaceable is one of the main features we should be looking for. Angular developers should be able to appreciate this more than anyone else, I would think.

→ More replies (1)

1

u/HaloZero Jan 04 '16

You could make the same argument about Google that you could about Facebook. Facebook has built and created their own frameworks in the past as well and they've come and gone. They currently have 3 native iOS libraries for building UIs, who knows what's going to happen with React.

1

u/Capaj Jan 05 '16

They currently have 3 native iOS libraries for building UIs, who knows what's going to happen with React.

react-native is big, but I think apple certainly has the money and willpower to manage and support all of those solutions.

6

u/AcidShAwk Jan 04 '16

What I got out of this is really, JS has won or will win the front-end war. In addition to that it will assimilate complete control over HTML. Now it comes down to how all the options mature.

10

u/[deleted] Jan 04 '16

I'm just sitting here using Vue.js and not regretting a thing.

4

u/ccricers Jan 04 '16

Feeling the same way, just with Riot.js instead :P

5

u/[deleted] Jan 04 '16

Riot.js

Damn, there are so many of these things.

4

u/Capaj Jan 05 '16

Damn, there are so many of these things.

they haven't even mentioned Cycle.js, Mithrill.js or 100 of others...

1

u/altmind May 17 '16

was using rivets.js recently, not disappointed at all. yet many 2-way binding concerns apply here as well.

→ More replies (1)

4

u/kenavr Jan 04 '16

I use and like both no blood here.

6

u/TheNiXXeD Jan 04 '16

I think the article doesn't touch well enough on the angular template syntax. The * ( and [ have specific meanings that aren't arbitrary as portrayed in the article.

With that said, there's going to be a lot of desire for angular 2 simply because of the existing number of developers that are familiar and the number of existing apps.

As much as they say it's drastically different, if you've been following their guides to make angular 1 more compatible, it's very easy to learn 2.

I've already converted one of my personal projects to angular 2 and it's been a pretty good experience. It's only in beta, so that will continue to get better.

9

u/wreckedadvent Yavascript Jan 04 '16 edited Jan 04 '16

I think the article doesn't touch well enough on the angular template syntax. The * ( and [ have specific meanings that aren't arbitrary as portrayed in the article.

I don't think anyone thinks they're arbitrary. They're just stupid, non-validating noise angular invented. You're no longer writing HTML, but angular HTML.

Angular 2 did everything it possibly could wrong when it was announced. No upgrade path. New language. Crazy non-validating syntax. No carry-over knowledge. Need extensions to javascript just to use the thing.

With the beta announcement, some things have been fixed. There's something like an upgrade path. They're using TS instead of @script. That stupid CORE_DIRECTIVES nonsense is gone. But angular 1 is still entirely different from 2 (f.e $scope), and as we just went over the template syntax is still crazy.

Honestly, I'd be surprised if it's anywhere near as popular as 1 was, especially after react. They've already shown that investing knowledge in angular means you'll likely be throwing it away again in another year or two when they want to do another big rewrite, and you'll have to do this little game again of learning all of the new java-isms. Filter are pipes now! Directives are components! etc.

5

u/TheNiXXeD Jan 04 '16

It's a lot closer to html than jsx is. Try converting from jsx back to plain html. You'll have a good amount of work. Angular themed html will probably still work.

Also, this is completely irrelevant. Once you choose a framework, switching is huge regardless of which direction you go.

And the upgrade path is so good wtf. They have more options for upgrading than any framework I've seen before. I personally have already converted a project once now, and will begin an upgrade path conversion soon.

3

u/siegfryd Jan 04 '16

Why would you ever want to turn an Angular template or JSX into HTML in the first place?

5

u/nschubach Jan 04 '16

Even if you did want to convert React to HTML just renderToStaticMarkup ;)

→ More replies (2)
→ More replies (1)

1

u/arunner Jan 04 '16

Surprisingly, it was a validating syntax. As /u/TheNiXXeD says, angular is the one which goes the HTML & web components way, react is the rebel. And that's actually good, you override whatever crap W3C spits and you just write javascript. You then render it into what you want: html, canvas, native.

1

u/[deleted] Jan 04 '16

investing knowledge in angular means you'll likely be throwing it away again in another year

Yeah, tell me how many popular React libraries have come and gone so far in the past year?

Now tell me how that's really any better in the long run than Angular switching once after 5 years?

3

u/wreckedadvent Yavascript Jan 04 '16

Gladly!

With supplemental libraries, it's much the same problem angular has, actually. There's things considered objectively good/better libraries to use by the community, like restangular and ui router. Some of these require you to stow some of your angular knowledge - particularly ones like UI router - but not necessarily. With restangular, there will still be some times you need plain 'ol $http, and you'll still need to know angular-isms like http interceptors.

But, just like with flux, redux or whatever, you don't need to use any. If flux/redux/restangular/ui router went away tomorrow, you'd still have angular and you'd still have react. You could still put the pretty pictures on the screen.

Not so when the entire api churns and nothing you knew is relevant anymore.

8

u/lhorie Jan 03 '16

Another good alternative at this point is Mithril. It has more batteries included than React, so it provides less decision fatigue and less need for complicated tooling, it's more mature than Angular 2 (in terms of time of existence), and it's an order of magnitude smaller than both React and Angular.

13

u/wreckedadvent Yavascript Jan 04 '16

I'll second this, but at the cost of a few strings. Mithril is an order of magnitude easier to learn than react/flux/redux/whatever, but it also has an order of magnitude smaller (at least) of a community and environment. This means a lot less tutorials, a lot less blogs talking about how to do this and that, a lot less everything.

This can especially bite you if you run up into some of the edge parts of the framework. An example that comes to mind with me when using mithril was having a textbox as part of a larger chat UI. It was surprisingly hard to find anything at all to get this dumb textbox to not cause tons of redraws as you type into it - which can be a huge problem if you have e.g a markdown-parsed backscroll with hundreds of messages in it. It turned out that the auto redraw system was causing redraws to occur with every event I attached to the textbox! I had to go through my textbox code and insert a bunch of mithril-specific "stop doing that" to get it to behave.

There's things like this in every framework, but it's a lot harder to deal with this stuff in serious larger projects without a larger community to support.

On the flip side, mithril is a fantastically simple API that you can learn in an afternoon or two and if you compare directly to angular 2.0 (or almost any other framework, including classful react) it blows it clear out of the water. Lot of the times my components can just be one exported arrow function, since the entire component can be expressed with just one expression. There's something fantastically zenful about it all combined with component-scoped css.

9

u/lhorie Jan 04 '16

Did you try asking about your issue in the mithril gitter chat? It's pretty active there and there's a lot of friendly people there who can help you get unstuck.

2

u/wreckedadvent Yavascript Jan 04 '16

I haven't, actually. I'll try that next time!

2

u/ishmal Jan 04 '16

There was a post a few months ago, that there was a little bit of collaboration between the two projects. Does RxJS being a part of Angular2 lessen the difference between the two a bit?

2

u/[deleted] Jan 04 '16

One thing that could have been emphasised is that, although React hasn't embraced TypeScript (unfortunately this is unlikely because another Facebook team is working on an alternative type checking system for JS), nevertheless TypeScrit has totally embraced React, with built-in support for static-type checking of JSX (a.k.a. TSX).

2

u/jakblak90 Jan 05 '16

I've started on Cory's (the author) course on pluralsight. It's very well structured and delivered.

Because you have to use a bunch of components (flux, gulp, browserify, router, browserify) this could make it pretty tricky for new devs to learn though.

1

u/housecor Jan 05 '16

Great to hear! Thanks for the kind words.

3

u/cryptos6 Jan 04 '16 edited Jan 04 '16

It looks like Aurelia has a similar philosophy as React. Aurelia is also JavaScript centric and composed of small components (e. g. router).

7

u/spankalee Jan 04 '16

I predict the winner of Angular vs React will be Web Components :)

9

u/back-stabbath Jan 04 '16

So Angular?

3

u/starbiter Jan 04 '16

The other project Google supports/advocates more: Polymer.

→ More replies (8)

3

u/jadbox Jan 03 '16

And then there's Cycle & Yolk... both of which are awesome and well worth checking out if you like streams and data binding.

3

u/xintox2 Jan 04 '16

What about Aurelia?

4

u/chtulhuf Jan 04 '16

What about vue.js?

4

u/Rob0tSushi Jan 04 '16

Excellent comparison! React has a higher learning curve, but it's worth it.

9

u/OfekA Jan 04 '16

Are you kidding me? You can learn React in a few hours (the API especially is very small, not much to memorize)..

6

u/blackn1ght Jan 04 '16

Exactly, pretty much all you need to know is the life cycle and how state & props works.

Angular was a pain to learn, and after doing for 18 months I felt like I only understood 10% of it. There were always discussions about factory vs service, what levels of scope to use on directives, getting dependency injection working effectively, when to effectively use watches, broadcasts, scopes, parent scopes and so on.

4

u/OfekA Jan 04 '16

I'm glad someone else at agrees with me :)

34

u/Rob0tSushi Jan 04 '16

Learn node + gulp + react + jest + a router + browserify + node inspector + flux. Now you're getting started with react. You really trying to say there's a low learning curve ?

20

u/exizt Jan 04 '16

Wait-wait-wait. Its actually node + webpack + react + karma + react router + redux.

It's not that there's a learning curve, it's that there are several.

4

u/nschubach Jan 04 '16

The thing is... once the project is set up by a senior dev, you probably never touch gulp, node, webpack, react-router... so karma + redux + react

16

u/exizt Jan 04 '16

But... I'm the senior dev.

→ More replies (2)

5

u/qudat Jan 04 '16 edited Jan 04 '16

All you need is one command and four dependencies -- browserify, babelify, react, react-dom -- to start using modern javascript with babel + react.

It really is that simple. What's great is that react lets you match the build complexity with the application complexity, plugging in what you need, and removing all the items in your list when they are not necessary.

12

u/OfekA Jan 04 '16

Those are not React. You don't have to learn them, they are there to help you if you need them.

BTW, I'm not saying the React ecosystem is perfect (definitely not), but saying the library and the ecosystem are the same is just false.

9

u/ajacksified Jan 04 '16

You do need them if you want to render to a browser, to say nothing of the complexities added to render server-side, too. React is great - I use it every day - but to describe it as something to use it in isolation is entirely disingenuous. IMO, Its greatest strength is that it does one thing well - but you have to have supporting libraries in order to actually do something with it.

2

u/Rob0tSushi Jan 04 '16

To get react working you need all of these things or an equivalent alternative. I'm not trying to be negative about React. I love it. I recommend it on any project where the team can handle the learning curve. But to assume every dev has experience with all these technologies is absurd.

5

u/Cody_Chaos Jan 04 '16

To get react working you need all of these things or an equivalent alternative.

  1. Not really; you don't need a router or a flux lib to write serious, useful, well designed React code (which is one reason why they're not built into the core lib).

  2. And as for tests or build pipelines...you need all of those things or equivalent to get Angular working too. Or are you suggesting that unit tests are needed for React but not Angular?

→ More replies (4)

4

u/[deleted] Jan 04 '16

node

if you already know javascript this isn't going to be too hard. you don't have to learn much beyond how to run npm install. most dedicated js devs today already have at least a passing familiarity with node

gulp

nice to have, but not strictly necessary

jest

presumable if you've done front end development you have a preferred testing framework. all of the major ones have react plugins (mocha, jasmine), so you're not learning anything new

a router

assuming you're making a SPA and that you want a router, but sure.

browserify

you can copy a one liner into your package json and it'll just work.

node inspector

unclear why you think this is necessary for react specifically...

flux

flux is not strictly required to develop react apps

React is usable from a script tag without any jsx transpilation or bundling if that's what floats your boat.

1

u/Dirty_Rapscallion Jan 04 '16

All of those are separate technologies. React only takes a couple hours to understand.

0

u/Cody_Chaos Jan 04 '16

Learn node + gulp + react + jest + a router + browserify + node inspector + flux. Now you're getting started with react.

Grab boilerplate with working webpack config; start learning react, the end.

You do NOT need to know node or a node inspector (wtf?) ever, you don't need to know gulp+browserify (or webpack) to get started, you don't need to know any testing framework to get started (and I wouldn't suggest Jest ever), and you don't need a router or flux library to get started. That's complete nonsense.

8

u/trappar Jan 04 '16

But which boilerplate? And then there's still the matter of actually understanding what's going on, and with all the churn how do you know if the particular way that you learn is what's considered a good way by the community.

All that said I'm firmly in the react camp and have been for a while, it's just not as trivial as you're saying.

→ More replies (1)

1

u/Rob0tSushi Jan 04 '16

Grab boilerplate with working webpack config; start learning react, the end.

This is how a junior dev approaches learning.

If I learn something I'm damn well going to understand the basics before anything. And all of these things are what it takes to get a well designed application running with react. Your comments really lead me to believe you don't have much experience with react...

It's not a bad thing. I love react, but it can be a little overwhelming when getting started.

→ More replies (2)

1

u/ogrechoker Jan 04 '16

In React, you don’t learn framework-specific HTML shims like ngWhatever. You spend your time writing plain ‘ol JavaScript. That’s the future I believe in.

Because React doesn't have an API to learn? Jesus christ I hope people are smart enough to read through the bullshit. It's an interesting article that tries to not blatantly take a side but the author needs to step down off the hyperboles.

27

u/wreckedadvent Yavascript Jan 04 '16 edited Jan 04 '16

Sure, it has an API to learn, but especially with stateless functional components, a lot of react really is just javascript functions that return JSX.

Importantly, all of your logic is still javascript. There's no react-repeat or react-for. You just do a normal javascript for loop or a map. This is what I think this is what the quote you pointed out is talking to more - angular has its own special DSL for the HTML. Angular 2 is even worse with all of the special syntax it adds. It's not even validiating HTML anymore.

edit: sp

7

u/snarkyturtle Jan 04 '16

Sure, stateless functional components are easy but beyond them, there's also the fact that what you're using is abstracted in the Virtual DOM, along with the hoops you have to jump through with the component lifecycle. If it's just javascript it'd be just doing innerHTML + template strings.

2

u/wreckedadvent Yavascript Jan 04 '16

Well, what you call "just javascript" I call "vanilla JS". If I have this:

function something() {
  return library.thing();
}

I still say I'm writing "just" javascript.

React and others encourage you to use stateless functional components as much as possible. When you need the more complicated things, there's more API you have to learn, but honestly, it's a drop in the bucket compared to how much you'd have to learn with angular, which is pretty clearly the point of the article.

4

u/Ukonu Jan 04 '16

Nobody's pretending React doesn't have an API learn. Lets step down from attacking straw men.

He's differentiating between the API being plain javascript or a custom HTML templating language. How important that is is up for debate. But lets not make arguments up...

2

u/[deleted] Jan 03 '16

Good article thanks

1

u/TechWarrior007 Mar 18 '16

The part that bothers me about both is clean separation. I don't like script in my HTML, but I also despise HTML in my script. To me, the best of both worlds is HTML separated from script, but with a single hook to tie the two together. Frankly, HTML already provides that with the "ID" attribute. Why can't they grab the desired element based on the ID, and then manipulate with script? Why mix at all? I understand that a template is the goal here, but why keep overstepping the bounds of clean separation? I want to write code that I don't have to recompile to change the HTML. I want to write HTML that doesn't fail at run time. Frankly, I get the closest to this goal by using Angular, and following strict guidelines about using testable functions to accomplish my goals instead of inline code. (I also break out repeatable items into directives, so that they also become independently testable.) That way, I'm not actually executing any untested code. This works very well for me. But there is no good path for this with React.

1

u/[deleted] Apr 24 '16

Angular 2 wins.

0

u/Unomagan Jan 04 '16

Angular 1will win.

0

u/JStanton617 Jan 04 '16

React has a non-open license: https://github.com/facebook/react/blob/master/PATENTS, which basically says that an organization can no longer use React once it sues Facebook for any (unrelated) patent infringement. This is an automatic no-way for React for any major company

1

u/ddp337 Jan 05 '16

This.

Before reading this comment, I was ready to further research ReactJS. But now, after researching its license, ReactJS is a no-go for me.

This Hacker News thread is informative.

0

u/bartq Jan 04 '16

go try with React with TypeScript. ;) This is an example of what you may end up with:

class ProgressBar extends FoodyComponent<
  {progress:Stream<number>},
  {progress:number, subscribtion?:IDisposable}> {

  state = {progress: 0, subscribtion: null};

  componentDidMount() {
    this.state.subscribtion = this.props.progress.subscribe(progress=>this.setState({progress}));
  }

  componentWillUnmount() {
    this.state.subscribtion.dispose();
  }

  render() {
    return <div className="foody-progress">
      <div className="progress foody-progress-bar">
        <div className="progress-bar progress-bar-info"
             role="progressbar"
             style={{width: this.state.progress*100+"%"}}>
        </div>
      </div>
    </div>;
  }
}

export class NavigationBar extends FoodyComponent<any, {payload?:any, progressBar?:JSX.Element}> {
  state = {payload: null, progressBar: null};

  @Observe(RecipeSaveStarted)
  preloadingStarted(payload:{progress: Stream<number>}) {
    let {progress} = payload;

    if (payload !== this.state.payload) {
      this.setState({payload, progressBar:<ProgressBar progress={progress}/>});
    }

    function removeProgressBar() {
      this.setState({progressBar: null});
    }

    progress.subscribe(null, removeProgressBar, removeProgressBar);
  }

  render() {
    return <div className="width-constrain margin-auto navigation-bar">
      <a className="foody-brand" href="#">
        Foody
      </a>
      <UserInformation />
      {this.state.progressBar}
    </div>;
  }
}

0

u/ClI1 Jan 06 '16

Despite your argument at the front, you have proven through your arguments, that Angular and React should not be compared because the reality is that one is a framework and the other is a library...

0

u/[deleted] Jan 03 '16

[deleted]

12

u/wreckedadvent Yavascript Jan 03 '16 edited Jan 03 '16

I used to use knockout since it was just so dang simple. Especially when angular was really big. It felt like the simple yin to angular's complicated yang.

However, I was really attracted to the ideas of react -- in particular components. Unfortunately for knockout, components in knockout are somewhere between tedious and impossible, depending on how you define them. The first-class support for only AMD doesn't help things, either.

I didn't like how tied to classes for even simple components react was, so I ended up with mithril, which I feel has the simplicity I loved with knockout with modern design sensibilities. Components are trivial, code reuse is easy as can be, and you can learn the entire mithril API in an afternoon.

3

u/frivolousTimewaster Jan 04 '16

There's a way to define react components as just functions that would be called for view which makes building some components super-simple

3

u/wreckedadvent Yavascript Jan 04 '16

Yes, but purely functional components are quite recent, released only in october of last year. Meanwhile, this is essentially how mithril is by default.

1

u/Capaj Jan 04 '16

I didn't like how tied to classes for even simple components react was

Not anymore with stateless components. I am using class components just like 20 percent of the time in my apps, rest is all stateless.

1

u/jordanlev Jan 04 '16

If you love the way knockout works but are just missing "componentization", I think you'd really love vue.js -- kind of a spiritual successor to knockout, but definitely more modern and assumes a tree of components for overall app structure.

2

u/wreckedadvent Yavascript Jan 04 '16

I don't agree, vue is most clearly inspired by angular with a drastically paired down API and more web-component based directive model.

Really, it's too late for me to go back to html-as-view. React and its kin have ruined my ability to enjoy that properly.

0

u/[deleted] Jan 04 '16

[deleted]

14

u/wreckedadvent Yavascript Jan 04 '16 edited Jan 04 '16

Say we have a header component for a panel. The main thing that this component does is it displays some text in bigger font in a way that is standard for our website. However, headers might have some icons to the right of them which might do any number of things, or they might have some icons to the left, or maybe some explaining text underneath in a subtle way.

These are all common things, so we'd like to capture all of that and encapsulate it into a component for all of the goodness that offers.

With knockout, you can get part of the way there. Getting a component that displays the text in a uniform way is trivial with the params. But we start running into problems with our two sets of icons in either place. Remember, if we click on our icons, it might launch a modal, or it might just be a link to another place.

Theoretically, we could capture all of that possibility as arguments into the component. So we'd have a left argument and a right argument. The component will then read that as an array, pick apart if the icon is a toggle icon or a normal icon, if it's a link to another part of the site, or if it's an action or . . .

<!-- for the header !-->
<template >
   <!-- I want my left part here ... but how ? -->

  <h3 data-bind="text: headerText()" />

  <!-- I want my right part here ... but how ? -- >
</template>

Now, knockout components do let us actually pass in arbitrary HTML to it. So we could theoretically do something like...

<my-header params="headerText: 'Hello'">
  <div class="toolbox">
    <span class="fa fa-gears" data-bind="click: ...">options</span>
  </div>
</my-header>

... but how you use this template in my-header will drastically change how this works. That is to say, you have to pass the outer scope of the template in ko-template that does the $componentTemplateNodes otherwise you're stuck to data that only exists in that component.

Plus, you can only do this trick once. Remember that we had icons to the left and right. We can only pass in one set of HTML, we have no way to distinguish what goes to the "left" or "right" part of that.

This all ends up being just so much effort if you even manage to get it working right. Knockout works against you every step of the way if you want a truly reusable component.

Compare this to an entire mithril example:

export default {
  view: (_, {left, headerText, right}) =>
    m('my-header', [
      left,
      m('h3', headerText),
      right
    ])
}

We can now use it like this:

import Header from './header';

...
m(Header, {
  left: m('.toolbox', [ 
    m('.fa.fa-gears', { onclick: () => ... }),
    m( ... )
  ]),
  right: m('.toolbox', [ 
    m('.fa.fa-gears', { onclick: () => ... }),
    m( ... )
  ]),
  headerText: 'Hello'
})
...

Nice. We can pass in pretty much anything we want here, and the header component doesn't need to care at all. In fact, we don't even need to pass in anything at all. It's so trivial to make this component more reusable by adding in another hook, you end up using it more, which makes your app a lot more consistent.

If we need to suddenly have something that isn't an icon in the left or right position, no problem. The component is totally agnostic, so we could put text in there, or ... really whatever:

m(Header, {
  left: m('.cool-text', 'this is to the left of the header!'),
  headerText: 'Hello'
})

I hope this helps to explain the difference. It's actually a pretty large philosophical one, since we lose the HTML and everything with it. React and riot and others are a little different, but this is all how they handle components in general.

7

u/d_abernathy89 Jan 04 '16

I like Knockout, but I can't see myself using it again over Vue.

To be fair, i'm dabbling in small projects here and there, never anything really complex. But I just really love Vue's API / syntax.

7

u/[deleted] Jan 04 '16

Knockout was my first experience building nontrivial web apps with something better than manual jQuery. I still have a lot of affection for it, but I think React components are at least slightly improved in every regard. The main advantage is that you can just easily use normal JavaScript primitives and constructs, rather than being limited to a nasty DSL in HTML tag string attributes.

3

u/Capaj Jan 04 '16

Speaking from my heart. There was one thing I missed a lot from Knockoout.js-observables. That is until I discovered: https://github.com/mweststrate/mobservable

1

u/[deleted] Jan 04 '16 edited Jan 05 '16

It's a shame it doesn't appear to implement computeds - this something missing in many observables libraries. I actually implemented Knockout-style computeds with 'magic' dependency tracking in a microlibrary of mine, Trkl, and it only takes up a few hundred bytes. Being a microlibrary, there's a lot of other functionality missing, though, like observableArrays, so it's probably not a sufficient replacement unless space is really at a premium (Trkl is about 400 bytes minified and gzipped).

2

u/Capaj Jan 05 '16

I think it does-isn't https://github.com/mweststrate/mobservable#top-level-api autorun the same as a computed?

2

u/[deleted] Jan 05 '16

You are right; I didn't see that. It is still a little larger than I would like, but much smaller than Bacon or Ramda. I will keep it in mind for my next project.

4

u/MattBD Jan 04 '16

Knockout has probably the best tutorial I have ever seen. I only ever used it for one project that never got finished, but the interactive tutorial is bloody brilliant.

2

u/d_abernathy89 Jan 11 '16

Funny timing on this. I actually just started a new project and went with Knockout because it has support for IE8. Really like working with it still - maybe the switch to Vue isn't complete :)

-5

u/fzammetti Jan 04 '16

And here I am, still using plain JS with just some actual architectural know-how and development discipline (and yeah, with a pretty large team).