Live data from Hacker News

What if we'd had better HTML-in-JS syntax all along?

leontrolski.github.io

91–100 of 170 posts

Re: What if we'd had better HTML-in-JS syntax all along?

#93

I think the JSX is just fine as an HTML-in-JS syntax. You can use JSX independently of React. Here's a 200-line library that lets you use JSX as a templating language just like Handlebars: https://github.com/wisercoder/uibuilder

What's the issue with web components that they have never took off?

Besides the poor browser support (supporting IE11 is still quite a pain) the API is just so bad that you'll need another abstraction on top anyway.

The main use right now is as target for framework independent design systems / component libraries.

Re: What if we'd had better HTML-in-JS syntax all along?

#94
post #62

The solution is not another templating language. Html is complex and many templating languages exist because it’s hard to compress and everything thinks it’s not that hard. There are so many things you need to do in HTML to make a modern web page that this suggestion conveniently ignores. The web is complex because it has replaced native programs and it’s perfectly backwards compatible. Stop trying to make it look ea…

> There are so many things you need to do in HTML to make a modern web page that this suggestion conveniently ignores.

Any examples of things that aren't handled by the suggested syntax?

Re: What if we'd had better HTML-in-JS syntax all along?

#95

The "object" syntax reminds me a lot of Clojure/script's Hiccup ( https://github.com/weavejester/hiccup ) style, which has become a de-facto standard across many popular libraries. In hiccup, this example: { tag: "button", attributes: { "id": "baz", "class": "foo bar", "data": "1", "onclick": f, }, children: [ "Hello", { tag: "em", attributes: {}, children: ["there"], } ] } Would be represented as: [:button#baz.foo.b…

That looks identical to WC3 XML Schema language using JSON syntax instead of XML syntax.

Re: What if we'd had better HTML-in-JS syntax all along?

#96

Earlier quoted context omitted.

What's the issue with web components that they have never took off?

Besides the poor browser support (supporting IE11 is still quite a pain) the API is just so bad that you'll need another abstraction on top anyway. The main use right now is as target for framework independent design systems / component libraries.

Here's an example of a Web Component: https://github.com/wisercoder/uibuilder/blob/master/WebCompo...

Looks pretty straightforward, and there isn't much of an API to begin with. It's just plain HTML, CSS, JavaScript and DOM APIs.

Re: What if we'd had better HTML-in-JS syntax all along?

#97
post #59

Earlier quoted context omitted.

> PHP code which supports being interspersed with HTML You're one of a large number of people who say this, but it is false. PHP intersperses a programming language with static strings. Those static strings frequently adhere to HTML syntax, but that's aside from PHP. What is HTML? It's not random strings; it's a syntax. JSX is much closer to interspersing HTML with a Turing-complete programming language than PHP ever…

You're technically correct, but I don't think the distinction adds anything to the conversation. I don't know if PHP was the inspiration for JSX, but if the strings they were using in PHP was HTML, then it could have been. EDIT: Sounds like JSX was inspired by XHP: https://www.facebook.com/notes/facebook-engineering/xhp-a-ne...

Besides, the parent never said that PHP was restricted to being mixed with HTML, they just said that it was possible. The contradiction of this is technically incorrect.

Re: What if we'd had better HTML-in-JS syntax all along?

#98
Writing UI's in pure functions is a kind of beauty. It's bit tedious without a framework, but you instead get full control and performance, and semantics. Btw, if your website is just static HTML like in the article, just write it in HTML (skip the JavaScript frameworks).

Re: What if we'd had better HTML-in-JS syntax all along?

#99
if this is about react then...xml inside javascript is for scrubs, just rename your createElement to 1 letter (mine is h) and use coffeescript lol.

i also renamed my "className" to "cn" so i dont have to type it but i wouldn't recommend that.

  h 'div',
    cn: 'myclass'
    h 'span',{},"mytext"
    h 'span,{},"asd"

Re: What if we'd had better HTML-in-JS syntax all along?

#100

Earlier quoted context omitted.

You can also take a look at mithril.js implementation of hyperscript [0] [0] https://github.com/MithrilJS/mithril.js/blob/next/render/hyperscript.js

was about to mention Mithril. solid framework, but not great for large applications.

What issues have you encountered that make it not great for large apps?
Post reply on HN