emberjs / group-helper

An experimental helper to change the granularity of bindings.
MIT License
86 stars 12 forks source link

#group & #with not working together. #4

Open julkiewicz opened 10 years ago

julkiewicz commented 10 years ago

I noticed issues concerning use of {{#group}} & {{#with}} in EmberJS 1.0 & 1.3:

Consider template file element.handlebars:

{{#group}}
  {{#each item in items}}
    {{#with item}}
      {{#if item.containedInParent}}
        {{#unless item.showWithControls}}
          <li>
            {{partial 'element'}}
          </li>
        {{/unless}}
      {{/if}}
    {{/with}}
  {{/each}}
{{/group}}

This seems to work with only a single level of recursion, i.e. nested {{#each}} never get rendered.

On the other hand the following:

{{#each item in items}}
  {{#group}}
    {{#with item}}
      {{#if item.containedInParent}}
        {{#unless item.showWithControls}}
          <li>
            {{partial 'element'}}
          </li>
        {{/unless}}
      {{/if}}
    {{/with}}
  {{/group}}
{{/each}}

seems to generate infinite recursion (tested in Chrome & Firefox).

Besides group-helper, is there any other place in EmberJS that sets insideGroup to true? Is the code path where insideGroup is true tested in any way in EmberJS?

julkiewicz commented 10 years ago

I should probably add: when I remove {{#group}}, everything works fine, the tree structure is rendered as it should.

stefanpenner commented 10 years ago

do you mind throwing down a jsbin or jsfiddle?

julkiewicz commented 10 years ago

Here's a jsfiddle demonstrating the problem:

Compare: http://jsfiddle.net/CbmmM/2/ and http://jsfiddle.net/CbmmM/4/

Once {{#group}} block is added, I get an exception undefined is not a function somewhere inside the {{#with}} tag.

julkiewicz commented 10 years ago

Actually, it seems it doesn't work even when no {{#with}} block is used. Basically, the variable bound by the loop becomes inaccessible. Doesn't cause an exception though.

julkiewicz commented 10 years ago

The {{#each}} tag however still iterates over the values.

julkiewicz commented 10 years ago

Any chance of having this corrected? I would be willing to contribute a patch if I had a clue how the feature works.

stefanpenner commented 10 years ago

@julkiewicz thanks for reporting this, someone will take a look as they have time.

jockee commented 10 years ago

Experiencing the same issue.

zackangelo commented 10 years ago

Also seems to happen if you assign the current item a different name in an each block (e.g. {{#each person in people}} {{/each}})