by msoad · 10y ago · 0 comments
<div *if={cond1 && cond2}>
<div>foo</div>
</div>
// results to
if (cond1 && cond2) {
return React.createElement('div', null,
React.createElement('div', null, 'foo')
);
}
I'm not sure why this is bad? Because it's looking like Angular?!! {cond1 && cond2
? <div>foo</div>
: null
} {(() => {
if (cond1 && cond2)
return <div>foo</div>
else
...
})()}
Though it makes GitHub think it's a Clojure file. {(() => {
})()}
Honestly I can't decide if I think this is ugly or beautiful. It's like the buffalo buffalo of JS. {do {
if (cond1 && cond2)
<div>foo</div>
else
...
}}
If JSX decides to implement "implicit" "do expressions", I suppose it would just look like this: {
if (cond1 && cond2)
<div>foo</div>
else
...
}
http://wiki.ecmascript.org/doku.php?id=strawman:do_expressio...note: i've changed your example to show code inside html tags, i'm aware it does something different to yours.
conditionals
<div>
@if(cond1 && cond2) {
<div>foo</div>
}
</div>
loops <div>
@for(var i in collection) {
<div></div>
}
</div>
variables <div>
@variable
</div>
ternary/longer statement <div>
@(variable ? 1 : 2)
</div>Maybe just a personal thing.
translates to
React.createElement('div', {if: <expression>})
This is bad because createElement always gets execute, whether the if expression evaluated to true or false. Changing this semantic would be messy.