TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Hamlet – Simple and powerful reactive templating

87 pointsby Yahivinalmost 11 years ago

16 comments

chengloualmost 11 years ago
Comparing your CoffeeScript example against a vanilla JS React example seems cheap. here&#x27;s the front page React example in CS:<p><pre><code> converter = new Showdown.converter() MarkdownEditor = React.createClass getInitialState: () -&gt; value: &#x27;Type some *markdown* here!&#x27; handleChange: (e) -&gt; @setState(value: e.target.value) render: () -&gt; d = React.DOM d.div( d.h3(null, &#x27;Input&#x27;), d.textarea(onChange: @handleChange, value: @state.value), d.h3(null, &#x27;Output&#x27;), d.div(dangerouslySetInnerHTML: __html: converter.makeHtml(@state.value)) ) React.renderComponent MarkdownEditor(), document.querySelector(&#x27;.container&#x27;) </code></pre> Showing a LOC comparison (and not even from the same dialect of a language) isn&#x27;t a good proof for what you&#x27;re trying to demonstrate. Clarity, simplicity, and debuggability all count. Removing a few extra lines of (non-boilerplate) code compared to React doesn&#x27;t make the library simpler to work with.
评论 #7902181 未加载
Tyr42almost 11 years ago
Oh, I thought this was the already existing Hamlet language.<p>Of which there are at least two.<p><a href="http://www.yesodweb.com/book/shakespearean-templates" rel="nofollow">http:&#x2F;&#x2F;www.yesodweb.com&#x2F;book&#x2F;shakespearean-templates</a><p><a href="https://github.com/gregwebs/hamlet.rb" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gregwebs&#x2F;hamlet.rb</a><p>It does look pretty cool though.
评论 #7901198 未加载
chriswarboalmost 11 years ago
An unfortunate choice of name. When I saw the title, I thought it was on about <a href="https://hackage.haskell.org/package/hamlet" rel="nofollow">https:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;hamlet</a>
评论 #7901906 未加载
评论 #7900914 未加载
评论 #7901587 未加载
评论 #7901119 未加载
评论 #7902035 未加载
bradgessleralmost 11 years ago
We use hamlc and Backbone.js in our stack. This lib looks like it will simplify a lot of that.<p>I have a few questions:<p>1. Its interesting to see JS events specified in the template (e.g. `%a(onclick=@doSomething)`). Is there a way to specify that in the JS&#x2F;model?<p>2. Does &quot;Observable&quot; mean that the value is updated when the model changes, when the DOM changes, or both? Could all of the attributes of the object passed into the template be observable by default or would that incur a significant performance penalty?
评论 #7900710 未加载
评论 #7900801 未加载
评论 #7901580 未加载
peterhuntalmost 11 years ago
&gt; Avoid working with over-engineered frameworks without sacrificing a great interactive experience<p>This is a pretty lame claim seeing as text fields are busted in Hamlet. [1]<p>This is another example of a &quot;lightweight&quot; library that hasn&#x27;t hit any of the hard problems yet. It&#x27;s fine if you make this your personal project to learn from, but trying to convince people to bet their projects on unproven technology is pretty disingenuous.<p>[1] Inserting characters does not work in the second example at <a href="http://hamlet.coffee/garden/" rel="nofollow">http:&#x2F;&#x2F;hamlet.coffee&#x2F;garden&#x2F;</a>
评论 #7901987 未加载
评论 #7902002 未加载
评论 #7901989 未加载
评论 #7901985 未加载
cfitzhughalmost 11 years ago
I&#x27;ve really enjoyed ractive. Simple to learn, with mustaches, and it has worked really well for our project. No extra compile steps. Figured I&#x27;d share since I see alot of buzz around React and other things, and preferred ractive.js when I researched it a little bit ago.
评论 #7907555 未加载
zeekayalmost 11 years ago
Would be extremely appealing if it borrowed more inspiration from Jade than Haml.
评论 #7900747 未加载
smrtinsertalmost 11 years ago
Reactivity is becoming an imperative. The browser of the future will let us code in a reactive language instead of forcing non reactive html or js on us. I&#x27;d love to see something simple for other languages and platforms as well.<p>I love that it seems to not be tied to node out of the box as well.
评论 #7900853 未加载
Smudgealmost 11 years ago
Got this JS alert: &quot;This website abuses rawgit.com. You should complain to its owner.&quot;
评论 #7901671 未加载
评论 #7901875 未加载
mquandallealmost 11 years ago
This looks to be a great declarative&#x2F;reactive template engine. I&#x27;ve been working mostly with the Meteor Blaze template engine the last few months. Both of them use a &quot;normal&quot; template language for writing views and (potentially) let you choose if you prefer writing your templates in Handlebars, Jade, or Haml [0], which I find far more easy to use than React JSX format. I think Blaze beats Hamlet on the runtime rendering engine.<p>First, Blaze does not require to set a root element in a template, which could be a source of bugs with Hamlet because for instance the `each` child is a template, here is a snippet of problematic example from the Hamlet README:<p><pre><code> - each @items, -&gt; .first .second </code></pre> This works perfectly fine in Blaze. IIRC Blaze uses comments node on the DOM that are never rendered in browsers in order to define some &quot;domrange&quot; that keep track of n children in a single parent group.<p>The second runtime issue in Hamlet appears when a third-party library directly modifies the DOM, without telling the template engine. Basically the modification will be erased on the next template redraw which make this system incompatible with all jQuery plugins for instance. Blaze has &quot;fined grained DOM updates&quot; which mean that the modification of a single element in a template does not require to touch any other node in the DOM. For instance if you have a each loop of inputs, and the user start to enter some data in one input field, and for some reason the template is redrawn the text will stay in the input with Blaze, but will be erased with Hamlet.<p>Blaze also support reactive SVG (I&#x27;m not sure if Hamlet supports it but I haven&#x27;t seen any particular mention in the code).<p>I think all of these features can be implemented in Hamlet drawing on Blaze and ReactJS runtimes.<p>Nevertheless I find the Javascript model declaration cleaner in Hamlet than in Blaze or Backbone or React. The only thing I&#x27;m not sure about is writing the js events in the template and not in the model, I actually like having all events of a given template in a single place but I don&#x27;t have strong opinion on this.<p>[0]: Meteor support Spacebars (which is quite similar to Handlebars) by default <a href="https://github.com/meteor/meteor/blob/devel/packages/spacebars/README.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;meteor&#x2F;meteor&#x2F;blob&#x2F;devel&#x2F;packages&#x2F;spaceba...</a>, and there is also a package for jade <a href="https://github.com/mquandalle/meteor-jade" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mquandalle&#x2F;meteor-jade</a> (disclaimer: I&#x27;m the author). It also seems that it wouldn&#x27;t be difficult to support other languages than Haml for Hamlet.
评论 #7901490 未加载
krickalmost 11 years ago
I&#x27;m more intrigued by the domain name. Why there even exists 1st level domain &quot;coffee&quot;?
coherentponyalmost 11 years ago
Oh wow, people are actually using these new TLDs.
评论 #7901473 未加载
jonahxalmost 11 years ago
@Yahivin, I&#x27;d love to hear your thoughts on Mithril. Have you used it?
评论 #7901435 未加载
bmcmastealmost 11 years ago
Looks really interesting. Any plans for a Rails Gem?
评论 #7901370 未加载
toisanjialmost 11 years ago
its too bad this is made for coffescript, i would have liked to see it for regular javascript.
评论 #7902277 未加载
notastartupalmost 11 years ago
What&#x27;s wrong with just using jQuery? what&#x27;s the rational for using a reactive solution?
评论 #7904780 未加载