TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Hyperscript Tagged Markup: JSX alternative using standard tagged templates

146 点作者 truth_seeker超过 6 年前

11 条评论

stevebmark超过 6 年前
The nice thing about React, vs others like Vue and Angular, is that we&#x27;ve learned not to write code in strings. You&#x27;d think this would be a fundamental law of software engineering, but we keep seeing things like<p><pre><code> v-bind:id=&quot;&#x27;list-&#x27; + id&quot; </code></pre> or<p><pre><code> &lt;button [style.color]=&quot;isSpecial ? &#x27;red&#x27; : &#x27;green&#x27;&quot;&gt; </code></pre> or this.<p>Writing code, not strings, means you can do everything to it that you can do to code. You can type check code. You can lint it. You can optimize it, compile it, validate it, syntax highlight it, format it with tools like Prettier, tree shake it...<p>That&#x27;s why I like JSX, it&#x27;s Javascript all the way down. Everything is code. It&#x27;s a very well designed and thought out DSL.
评论 #18512253 未加载
评论 #18513813 未加载
评论 #18511998 未加载
评论 #18512528 未加载
评论 #18514067 未加载
评论 #18515925 未加载
评论 #18513082 未加载
评论 #18514312 未加载
评论 #18512126 未加载
评论 #18511996 未加载
评论 #18512073 未加载
评论 #18512575 未加载
mattbierner超过 6 年前
I’ve written tooling to support lit-html and styled-components in editors. Template strings are sort of nice to write but complete pain to support in editors. They are just like a macro language, so you end up with stuff like: `&lt;${tag}&gt;...&lt;${tag}${slash}&gt;` which is not possible in jsx. Even just detecting syntax errors is a pain<p>Obviously if deciding between making life easy for editor implementers or making life easier for coders, the coders win, but if something is unnecessarily difficult to build good tooling for, that’s a sign of poor design in my book. And coders will ultimately suffer too because their tooling will suck and because their code will make use of all the crazy flexibility the library allows.
评论 #18512466 未加载
mbostock超过 6 年前
This is lovely for using React or Preact in Observable!<p><a href="https:&#x2F;&#x2F;beta.observablehq.com&#x2F;@mbostock&#x2F;hello-htm" rel="nofollow">https:&#x2F;&#x2F;beta.observablehq.com&#x2F;@mbostock&#x2F;hello-htm</a><p>We have our own lit-html-inspired html tagged template literals that render directly to DOM, but it’s nice to see HTM’s improved support for function attributes (e.g., onclick), spread attributes, etc.
评论 #18512105 未加载
mhd超过 6 年前
I remember when everyone suggested their own way of s-expressions (basically) to avoid having to write superfluous end-tags and other XML&#x2F;HTML tchotchkes, now we&#x27;re getting multiple ways to get all the markup boilerplate into our programming language.<p>Sometimes it&#x27;s weird how tastes change. Same thing happened with the nigh universal hacker-ish dislike of &quot;bondage and discipline&quot; languages, now it&#x27;s enforced formatting wherever you look.
评论 #18514404 未加载
leowoo91超过 6 年前
Can we go back to Jinja now?
评论 #18512332 未加载
评论 #18511795 未加载
评论 #18511845 未加载
lucideer超过 6 年前
&gt; <i>Improvements over JSX</i><p>With the exception of html comments, these are invariably antifeatures. Optional quotes&#x2F;closing tags save zero to negligible typing time in exchange for added complexity for tooling and reduced readibility in many circumstances.<p>I can understand why these features were added to HTML5 (backward compatibility is of more benefit than prescriptivism) but I would never have thought anyone would argue that having these features in HTML1 was a good idea in retrospect!?<p>Adding them to a new syntax that isn&#x27;t burdened with backward compat requirements seems daft.
sddfd超过 6 年前
How is this different from lit-html?<p><a href="https:&#x2F;&#x2F;github.com&#x2F;Polymer&#x2F;lit-html" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Polymer&#x2F;lit-html</a>
评论 #18511577 未加载
评论 #18512383 未加载
dixie_land超过 6 年前
TIL <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Template_literals#Tagged_templates" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Refe...</a><p>I&#x27;m not a JavaScript developer so this is news to me, very neat feature!
评论 #18512059 未加载
qwerty456127超过 6 年前
IMHO the name choice (htm) is really bad.
评论 #18512462 未加载
bcherny超过 6 年前
This is a neat syntax, but it doesn’t seem at all typesafe (typesafety was the main benefit of JSX over the various string templates that came before it).
评论 #18512145 未加载
评论 #18511513 未加载
drivingmenuts超过 6 年前
So,I guess mixing presentation and logic is OK now? &#x27;Cos as a PHP programmer I used to get shat on all the time for that and I&#x27;d like a chance to, you know, unload on someone else for a change.<p>NM, I&#x27;ll just go back to my cave now.
评论 #18511986 未加载
评论 #18511872 未加载