by Offler · 11y ago · 0 comments
const links = ctrl.pages().map(page => <a href={page.url}>{page.title}</a>);
return <div> {links} <button onClick={ctrl.rotate}> Rotate Links </button> </div>;
Compared to
m("div", [
ctrl.pages().map(function(page) {
return m("a", {href: page.url}, page.title);
}),
m("button", {onclick: ctrl.rotate}, "Rotate links")
]);
I can see what the UI will be with JSX at a glance with Mithril I have to parse the code.edit: Mind you both look awful due to HNs poor formatting ability. Honestly how did this website become so popular with tech people?
React:
const links = ctrl.pages().map(page => <a href={page.url}>{page.title}</a>);
return <div> {links} <button onClick={ctrl.rotate}> Rotate Links </button> </div>;
Mithril: const links = ctrl.pages().map(page => m("a", {href: page.url}, page.title));
return m("div", [links, m("button", {onclick: ctrl.rotate}, "Rotate links")]);
There are JSX equivalents for Mithril too (for both Babel and standalone JSX).Mithril templates look also very good in CoffeeScript and similar languages.
Both of those snippets are intended to generate HTML. In that sense there's no question which one is easier to reason about/read.
I would argue the opposite — it is immediately easier to reason about, since I see what functions are called, and I can go look up the documentations for those functions without having to go through a precompile-step.
What would make it "hard" to read? The fact that the third argument is the text?
That's just a tiny convention.
[:div
(for [p ctrl.pages]
[:a {:href p.url} p.title])
[:button {:onclick ctrl.rotate} "Rotate links"]]You mean use clojure(script) , don't be shy ...
The rudimentary formatting keeps away the high-noise/low-signal folks who need shiny bells and whistles with their tech discussions.