Show HN: Moon – 3kb JavaScript UI compiler
kbrsh.github.io
kbrsh.github.io
<For={item in items}>
<!-- multiple elements -->
</For>
<p For={item in items}><!-- single element --></p>
This syntax works for every component ("For" is just another component). <ul>
<li v-for="item in items">[...]</li>
</ul>
It is something you do have to remember. I believe you can use a template tag too if you like.No, you also have to relearn, just not as much. The React docs rightly state "JSX is not HTML" because you cannot use comments, doctype and it's a shame that JSX deviates from HTML in attribute names. Having to use className instead of class annoys me to no end and is why I prefer preact (they use class). Also autoComplete and spellCheck - just why? Converting this-that to thisThat makes sense but renaming attributes without necessity was a stupid decision.
Class is a reserved word. This is why they stuck with the dom attribute names. Because it is JS, not html :)
If you need to merge it with some statically applied class names in your component you need to access it. This is an absolutely common thing. It would be terrible if i'd need to access it by using a string. And even then I would need to assign it to a name other then "class" which makes it even more confusing then naming it "className" by convention.
So if you imagine that it's going through performing a document.createElement() call for each node then setting attributes then it makes sense. The only alternative is to maintain a list of mappings from HTML attribute to JS DOM attribute as part of the library, which would be a waste of bandwidth and irritating to maintain. The real problem is that JSX looks like HTML but is not describing HTML.
Actually, that's a React issue, not a JSX one.
JSX is attribute agnostic. You can use it with another view library like Mithril and not worry about those shenanigans (class, autocomplete and spellcheck will work out of the box).
Also if you use a sophisticated IDE that shouldn't be an annoyance at all.
But not only does it mean that users don't have to learn a new language and concepts, but it mean the maintainers don't have to develop a new language and all the corner cases, feature requests and bugs that come with it.
And in the case of lit-html, you also eliminate compilers completely because there's also no non-standard markup-in-JS syntax.
m2.textContent = instance.text;
Use Moon.compile(template) to get a better idea of outputs.It is the best mix of expressiveness, ease, and clarity I've found.
A keyed implementation, single-file components (multi-file components exist with Moon CLI but I've started to like single-file components), custom DOM events, component inserts, and an official router are on my todo list. Hopefully you'll get to use the library this time :)
Now I have worked on designing a new structure for web applications that I’m planning on writing further about. The view API of components in Moon closely models my vision for the future of the web. Moon’s philosophy is to have a consistent API in order to create views to display data.
:)
A weird fixation.
https://news.ycombinator.com/item?id=15156363
If he's 14, then he's pretty much an attention needing dude (as he submitted this moon library at least 5 times and his "I'm 13 yo" tweets at least 3 times). At the same time, he claims that he does not like to mention his age.