News for hackers. Stuff that matters.
Re:Hamlet – Simple and powerful reactive templating by bradgessler on Monday June 16, 2014 @02:33PM (#7900656)
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?

Re:Hamlet – Simple and powerful reactive templating by Yahivin on Monday June 16, 2014 @02:42PM (#7900710)
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.

Re:Hamlet – Simple and powerful reactive templating by klibertp on Monday June 16, 2014 @02:51PM (#7900752)
When is the DOM updated? Are the changes performed as soon as they are observed or are they queued? Does Hamlet implement some kind of "virtual DOM" for diffing or does it sync DOM and model directly?

Looks very nice, just this weekend I looked at some frontend frameworks, including Vue, Mithrill, Ractive and React and found some issues with them all. Hamlet would fit my use case very well, I think. One thing I'd like is more technical details on the main page - not how it "looks like" compared to other frameworks, but how it does its thing (compared to other frameworks).

Re:Hamlet – Simple and powerful reactive templating by rich_harris on Monday June 16, 2014 @02:56PM (#7900787)
Thanks for trying Ractive (I'm on the core team). If you don't mind, I'd be interested in knowing what issues you came up against with those frameworks that you listed?
Re:Hamlet – Simple and powerful reactive templating by Yahivin on Monday June 16, 2014 @02:56PM (#7900789)
The current implementation performs changes immediately. There is no virtual DOM, as soon as a change occurs the model is update and vice versa.

The Observable component invokes the callback to all listeners immediately when its value is changed. I find this makes testing and debugging somewhat easier than async callbacks or nextTick.

Re:Hamlet – Simple and powerful reactive templating by bradgessler on Monday June 16, 2014 @03:06PM (#7900849)
How does observable wrap values? I see a few things:

  list = Observable []
  list.push 'blah'
and

  isOrange = Observable false
  isOrange = true // This obviously doesn't work this way...
Do you poll the value? Or do you check the type of the value and wrap/proxy methods that would normally change the value?
Re:Hamlet – Simple and powerful reactive templating by Yahivin on Monday June 16, 2014 @03:14PM (#7900906)
When Observable is declared with a type (especially an array) it sets up some wrapped methods to simplify working with it.

The wrappers also set up automatic dependency resolution so you can do cool things like:

    list = Observable []

    reversed = Observable ->
      list.map reverse

    list.push 'blah'

    reversed() # => ['halb']
There's no polling, the observable notifies all observers immediately when the value changes.
Re:Hamlet – Simple and powerful reactive templating by bradgessler on Monday June 16, 2014 @03:57PM (#7901125)
What about simple types, like the `false` value example above? Is there a `set` and `get` method?
Re:Hamlet – Simple and powerful reactive templating by mdiebolt on Monday June 16, 2014 @04:02PM (#7901152)
You'd use a jQuery style setter.

  isOrange(false)
Re:Hamlet – Simple and powerful reactive templating by peterhunt on Monday June 16, 2014 @06:22PM (#7901818)
What issues did you find with React?
Re:Hamlet – Simple and powerful reactive templating by Dorian-Marie on Monday June 16, 2014 @02:59PM (#7900801)
I see you can also use `%button(click=@hello) Hello!` in the example page: http://hamlet.coffee/garden/
Re:Hamlet – Simple and powerful reactive templating by Yahivin on Monday June 16, 2014 @03:02PM (#7900824)
That's correct. Both styles of event names are supported!
Re:Hamlet – Simple and powerful reactive templating by pbiggar on Monday June 16, 2014 @05:28PM (#7901580)
We use hamlc and knockout: this seems like a wonderful improvement. If only we weren't 80% of the way to cljs+om.