Showing a LOC comparison (and not even from the same dialect of a language) isn't a good proof for what you're trying to demonstrate. Clarity, simplicity, and debuggability all count. Removing a few extra lines of (non-boilerplate) code compared to React doesn't make the library simpler to work with.
I thought about that when constructing the demo but opted to use the JSX / plain JavaScript version because that's what's displayed on the React homepage.
We have a strong preference for Haml and CoffeeScript dialects so that's how we present our demos. I built jsfiddles based on how each framework presented their own product.
We use hamlc and Backbone.js in our stack. This lib looks like it will simplify a lot of that.
I have a few questions:
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/model?
2. Does "Observable" 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?
For point one, it is specified in the model. @doSomething would invoke the model's doSomething function. The template just names it.
As to point two, observable provides a bi-directional binding so that changes to the value are reflected in the DOM and changes in the DOM are reflected in the model.
The observable interface is essentially a jQuery style getter/setter method that allows for observers to be notified of changes.
> Avoid working with over-engineered frameworks without sacrificing a great interactive experience
This is a pretty lame claim seeing as text fields are busted in Hamlet. [1]
This is another example of a "lightweight" library that hasn't hit any of the hard problems yet. It'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.
One thing I would love on HN is the reluctance to say something is "lame" because one example doesn't work for one person on one browser. Instead of being dismissive, why not be constructive? Or if you can't even do that, just don't post?
I've really enjoyed ractive. Simple to learn, with mustaches, and it has worked really well for our project. No extra compile steps. Figured I'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.
I actually agree! I started with haml because it's what I knew best at the time.
The parser is separate from the compiler and the runtime, so it should be simple enough to add a jadelet, anglet, or any other simple style of adapter.
If there is a lot of interest in a jade focused style or haml is a turn off for many people then it will become a priority for us.
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'd love to see something simple for other languages and platforms as well.
I love that it seems to not be tied to node out of the box as well.
One of our goals was for Hamlet to be suitable for really small and simple web apps, without any big framework or ecosystem. There's still a lot of work for us to do on the ease of getting started (both with or without node) so if you run into trouble or have any comments let us know.
This looks to be a great declarative/reactive template engine. I've been working mostly with the Meteor Blaze template engine the last few months. Both of them use a "normal" 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.
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:
- each @items, ->
.first
.second
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 "domrange" that keep track of n children in a single parent group.
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 "fined grained DOM updates" 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.
Blaze also support reactive SVG (I'm not sure if Hamlet supports it but I haven't seen any particular mention in the code).
I think all of these features can be implemented in Hamlet drawing on Blaze and ReactJS runtimes.
Nevertheless I find the Javascript model declaration cleaner in Hamlet than in Blaze or Backbone or React. The only thing I'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't have strong opinion on this.
That issue about requiring a root item should be solvable in the future, it's just the current implementation that has limitations. I'm building up the test suite to specify the behavior and hope to have it working soon.
For the most part jQuery plugins should work fine with Hamlet, so long as one remembers to update the data in the model rather than arbitrarily throughout the DOM. It can be a moderate mental shift to go from jQuery style "The DOM is the data" to the newer Backbone, Knockout, React, Angular, etc style of "The model is the data" and may not be right for all applications.
Thanks for the comment I'll take a look at Meteor Blaze and see what cool tricks it has :)
I hadn't seen Mithrill before, but from checking it out now it looks like it has a lot in common: small runtime, trying to be as close to plain JS and DOM as possible, and safety by default.
I'm not sure if it provides as much magic as Hamlet's auto-dependencies and template syntax, but those do have costs and tradeoffs.
I would like to see an interactive demo on the site so I could get to know it better by messing around.
Yes, we plan to create or assist the creation of drop in solutions for Rails, Sinatra, and popular node frameworks, priority based on interest, volunteers, and whoever demands it the loudest.
Say you're building a color picker with three text fields for R, G, B, and a swatch that displays the resulting color.
You could do it in jQuery, but plumbing all the update code for each input would be kind of a chore. If you get a new source of input (say from the network) you'd have to remember to resync everything. To keep it simple you'd probably have to respond to `something changed` -> `update everything`. Reactive templates would only update the elements dependent on that change.
With a reactive solution you make a model that contains observable RGB values and a function to compute the final color. Once you bind that model to your view everything stays in sync like magic.
[+] [-] chenglou|11 years ago|reply
[+] [-] mdiebolt|11 years ago|reply
We have a strong preference for Haml and CoffeeScript dialects so that's how we present our demos. I built jsfiddles based on how each framework presented their own product.
[+] [-] Tyr42|11 years ago|reply
Of which there are at least two.
http://www.yesodweb.com/book/shakespearean-templates
https://github.com/gregwebs/hamlet.rb
It does look pretty cool though.
[+] [-] Grothendieck|11 years ago|reply
[+] [-] chriswarbo|11 years ago|reply
[+] [-] EGreg|11 years ago|reply
[+] [-] Yahivin|11 years ago|reply
[+] [-] progrium|11 years ago|reply
[+] [-] cstrahan|11 years ago|reply
[+] [-] dllthomas|11 years ago|reply
[+] [-] bradgessler|11 years ago|reply
I have a few questions:
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/model?
2. Does "Observable" 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?
[+] [-] Yahivin|11 years ago|reply
As to point two, observable provides a bi-directional binding so that changes to the value are reflected in the DOM and changes in the DOM are reflected in the model.
The observable interface is essentially a jQuery style getter/setter method that allows for observers to be notified of changes.
[+] [-] Dorian-Marie|11 years ago|reply
[+] [-] pbiggar|11 years ago|reply
[+] [-] peterhunt|11 years ago|reply
This is a pretty lame claim seeing as text fields are busted in Hamlet. [1]
This is another example of a "lightweight" library that hasn't hit any of the hard problems yet. It'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.
[1] Inserting characters does not work in the second example at http://hamlet.coffee/garden/
[+] [-] CanSpice|11 years ago|reply
One thing I would love on HN is the reluctance to say something is "lame" because one example doesn't work for one person on one browser. Instead of being dismissive, why not be constructive? Or if you can't even do that, just don't post?
[+] [-] CGamesPlay|11 years ago|reply
[+] [-] mdiebolt|11 years ago|reply
Could you let me know which browser and version you're using so I can get to the bottom of the problem?
[+] [-] Yahivin|11 years ago|reply
What browser and OS are you using? The examples have worked in our testing environments of Chrome, FF, IE9+, Safari, and Opera.
[+] [-] cfitzhugh|11 years ago|reply
[+] [-] Yahivin|11 years ago|reply
[+] [-] zeekay|11 years ago|reply
[+] [-] Yahivin|11 years ago|reply
The parser is separate from the compiler and the runtime, so it should be simple enough to add a jadelet, anglet, or any other simple style of adapter.
If there is a lot of interest in a jade focused style or haml is a turn off for many people then it will become a priority for us.
[+] [-] smrtinsert|11 years ago|reply
I love that it seems to not be tied to node out of the box as well.
[+] [-] Yahivin|11 years ago|reply
One of our goals was for Hamlet to be suitable for really small and simple web apps, without any big framework or ecosystem. There's still a lot of work for us to do on the ease of getting started (both with or without node) so if you run into trouble or have any comments let us know.
[+] [-] Smudge|11 years ago|reply
[+] [-] Yahivin|11 years ago|reply
[+] [-] mdiebolt|11 years ago|reply
[+] [-] mquandalle|11 years ago|reply
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:
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 "domrange" that keep track of n children in a single parent group.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 "fined grained DOM updates" 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.
Blaze also support reactive SVG (I'm not sure if Hamlet supports it but I haven't seen any particular mention in the code).
I think all of these features can be implemented in Hamlet drawing on Blaze and ReactJS runtimes.
Nevertheless I find the Javascript model declaration cleaner in Hamlet than in Blaze or Backbone or React. The only thing I'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't have strong opinion on this.
[0]: Meteor support Spacebars (which is quite similar to Handlebars) by default https://github.com/meteor/meteor/blob/devel/packages/spaceba..., and there is also a package for jade https://github.com/mquandalle/meteor-jade (disclaimer: I'm the author). It also seems that it wouldn't be difficult to support other languages than Haml for Hamlet.
[+] [-] Yahivin|11 years ago|reply
For the most part jQuery plugins should work fine with Hamlet, so long as one remembers to update the data in the model rather than arbitrarily throughout the DOM. It can be a moderate mental shift to go from jQuery style "The DOM is the data" to the newer Backbone, Knockout, React, Angular, etc style of "The model is the data" and may not be right for all applications.
Thanks for the comment I'll take a look at Meteor Blaze and see what cool tricks it has :)
[+] [-] krick|11 years ago|reply
[+] [-] coherentpony|11 years ago|reply
[+] [-] mdiebolt|11 years ago|reply
[+] [-] jonahx|11 years ago|reply
[+] [-] Yahivin|11 years ago|reply
I'm not sure if it provides as much magic as Hamlet's auto-dependencies and template syntax, but those do have costs and tradeoffs.
I would like to see an interactive demo on the site so I could get to know it better by messing around.
[+] [-] bmcmaste|11 years ago|reply
[+] [-] Yahivin|11 years ago|reply
[+] [-] toisanji|11 years ago|reply
[+] [-] Yahivin|11 years ago|reply
[+] [-] notastartup|11 years ago|reply
[+] [-] Yahivin|11 years ago|reply
You could do it in jQuery, but plumbing all the update code for each input would be kind of a chore. If you get a new source of input (say from the network) you'd have to remember to resync everything. To keep it simple you'd probably have to respond to `something changed` -> `update everything`. Reactive templates would only update the elements dependent on that change.
With a reactive solution you make a model that contains observable RGB values and a function to compute the final color. Once you bind that model to your view everything stays in sync like magic.