roundlake/joosy — Issue #3: Closure bug in renderer's @widget
Author: GearHead90
Created: 2012-02-05 13:04:19+00:00
State: open

Given we have @items with 20 entries.
Following code in template:

- for item in @items
!= @widget 'article', -> new ItemWidget(item)

It is compiled to

for (_i = 0, _len = _ref.length; _i < _len; _i++) {
item = _ref[_i];
$o.push("" + $c(this.widget('article', function() {
return new ItemWidget(item);
})));

Anonymous function with new ItemWidget will be called, when cycle in template is already done, and item is last of @items. So widget will be rendered 20 times with one last entry.

As expected, this code works:

- t = (item) -> return (-> new ItemWidget(item) )
- for item in @items
!= @widget 'article', t(item)