Let's not forget how horrible Angular templating was:
<ul ng-if="::vm.items.length">
<li ng-class="::{ 'active': item.active }" ng-repeat="item in ::vm.items | orderBy: 'id' as ordered track by item.id" ng-click="item.active = !item.active">
{{::item.name}}
</li>
</ul>
<select ng-options="item.subItem as item.label for item in ::vm.items2 track by item.id" ng-model="selected"></select>
<div ng-include="selected.template.url" />Syntactically, JSX feels more native, but both are addressing the same problem.
Edit: After reading my comment again, I feel I must mention; even that similarity is not coming from React directly. It's JSX. Although they go like fish & chips together (Not a great analogy but I guess I'm hungry).
It's a templater, read my message above - an advanced tempalter, which means it has some DOM rendering optimizations.
> The only similarity between PHP and React is that you can have tags in ("around" in PHP's case) your code.
Not just tags, but an entire "view" thing, a representation, so old fashion messy/sloppy/spaghetti-like PHP like code style.
For PHP (in its traditional form), everything around the code is just strings, which is also the case for most of the templating engines.
You can't shout "spaghetti code" every time you see XML tags in code. Think Scala or VB.
the notion that your view logic and it's template must be completely decoupled is an antiquated and misguided best practice.
Really want to play with it ...
Why is this good?
1. Let's say I want to stick a debugger in my template or render function. How would you do it in Vue? Angular? I don't know, gotta look it up, not even sure if possible. How would you do it in React? I don't have to look anything up, I just have to think (use an iife):
<div>
<SomeComponent
debug={(() => { this.state; debugger; })()}
someProp="prop"
/>
</div>
2. Let's say I want to use Immutable.JS instead of plain js arrays. How would I iterate over an immutable list in Vue. In Angular? I don't know, probably have to download some third party directive. React: <ul>
{immutable.toSeq().map(x => <li>x</li>)}
</ul>People seem to think using a familiar templating language excludes using the full power of JavaScript. It doesn't.
{{ data | json }}
will give you formatted json output of the data object (i.e. state/props) In reality you can put anything that's in the Vue object's scope between curly braces, pipe it through the json filter.>immutable list in Vue
<li class="for-example" v-repeat="item in list">{{item}}</li>So neither debugger support nor printf-debugging, you just have to hope you'll be dumping garbage in a place where it can be seen and doesn't break the page entirely?
> <li class="for-example" v-repeat="item in list">{{item}}</li>
Ignoring that vue changed the name of the directive a while ago[0] that doesn't even remotely work, according to its documentation v-for (née v-repeat) works on native arrays, it's not going to work in any sensible manner on immutable.js structures.
The bad thing about most other template DSLs is that they recreate all of these features from scratch, often in buggy ways. For example, many template DSLs have dynamically scoped variables instead of lexically scoped ones.
JSX:
<div className="classy" onClick={this.handleClick} />
No JSX: React.createElement('div', {
className: 'classy',
onClick: this.handleClick,
});
Native (note this naive implementation lacks proper scoping): var el = document.createElement('div');
el.className = 'classy';
el.onclick = handleClick;
This has been available on all major browsers for quite some time, React just provides some convenience around it and a sugar for those that prefer code that looks like HTML because people tend to (fairly, imo) associate their HTML with the state of the DOM.It's really much like JSX, but without the syntactic sugar of using HTML-like markup.
https://medium.com/@housecor/react-s-jsx-the-other-side-of-t...