<a href="...">Link 1</a> |
<a href="...">Link 2</a> |
<a href="...">Link 3</a>
It's not Link 1 | Link 2 | Link 3
as you'd expect - instead, the whitespace after the pipe character is eaten by JSX. This is because HTML is whitespace sensitive, but JS is not, and so to allow indentation, JSX trims whitespace.Here's another -
<dl>
{ Object.entries(definitions).map(([term, definition]) => (
<dt>{ term }</dt>
<dd>{ definition }</dd>
)}
</dl>
This does not work - instead, you need to return an array, but the result is ugly - the commas are part of JS, not HTML, and don't appear in the output, but reading this quickly it's hard to see that (the difference is the braces surrounding the block). <dl>
{ Object.entries(definitions).map(([term, definition]) => ([
<dt>{ term }</dt>,
<dd>{ definition }</dd>,
])}
</dl>
Vue's 'weird DSL' is HTML (the same is not quite true for Angular's). What you see is exactly what you get. Having a DSL also means you can define your own syntax. Things that are verbose (due to historical reasons in JS), such as iterating over an object, can be made simple - <dl>
<template v-for="(definition, term) in definitions">
<dt>{{ term }}</dt>
<dd>{{ definition }}</dd>
</template>
</dl>You still have to understand html inside weird jsx code...
{' '}
Not the prettiest, but doesn't come up often in my experience.On the 2nd point, you are partially correct. In general it's a code smell - strongly consider making it a component (in part for optimization). But definition lists are specifically strange: Unlike other repeating elements in HTML they don't have a container element like tr, li, fieldset, etc.
<button v-bind:disabled="isButtonDisabled">Button</button>
<div v-bind:id="'list-' + id"></div>
<form v-on:submit.prevent="onSubmit"></form>
<a @click="doSomething"></a>
Something tells me JSX is the better DSL. <button :disabled="isButtonDisabled">Button</button>
<div :id="'list-' + id"></div>
<form @submit.prevent="onSubmit"></form>
<a @click="doSomething"></a>
It gets really, really clear that anything not in {{ }}, or attribute not prefixed by @ or : is HTML.The only way I see that as being more "intuitive" is if you're familiar with other templating languages.
JSX is far clearer:
<button disabled={isButtonDisabled}>Button</button>
<form onSubmit={handleSubmit}></form>
<a onClick={doSomething}></a>
All you really need to know is everything between braces is plain JavaScript, and property names are camelCased.I have a Typescript + Angular 1 project. The app logic feels robust as Typescript makes sure I'm using the right identifiers, variables aren't null/undefined etc. The Angular templates are a constant source of annoyance: they aren't type checked and aren't part of automatic variable renaming refactorings.
Can someone confirm that you cannot type check Vue.js templates (without using Vue.js JSX support of course)?
For the Angular 1 project, I'm thinking as a stepping stone we could introduce JSX templates before migrating to Vue or React later.
Of course this only really matters if you use Typescript/Flow.