Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support key option in each-in helper #541

Closed
LanceStasinski opened this issue Mar 13, 2023 · 3 comments · Fixed by #558
Closed

Support key option in each-in helper #541

LanceStasinski opened this issue Mar 13, 2023 · 3 comments · Fixed by #558
Labels
bug Something isn't working question Further information is requested

Comments

@LanceStasinski
Copy link
Contributor

The key option in the {{#each}} and {{#each-in}} helpers are useful for improved rendering of elements generated by arrays and objects. Currently, glint supports key the {{#each}} helper, but it is not supported for {{#each-in}}. For example

get object() {
  return {
    first: [1, 2, 3],
    second: [4, 5, 6],
    third: [7, 8, 9]
  }
}
{{#each-in this.object key='@key' as |key value|}}
  <div>{{key}}: {{value}}</div>
{{/each}}

produces this typescript error:

Argument of type '{ key: string; }' is not assignable to parameter of type 'EmptyObject'. Object literal may only specify known properties, and 'key' does not exist in type 'EmptyObject'.

The key='@key' syntax is supported by glimmer and is mentioned by this bugfix (admittedly, there's not a whole lot of documentation of the key option for the {{#each-in}} helper.)

@chriskrycho chriskrycho added the bug Something isn't working label Mar 14, 2023
@chriskrycho
Copy link
Member

I've marked this as a bug, and if we confirm that it's intended as public API, we should likely implement it, but it's definitely not documented anywhere! That could just be a miss—it's possible it was intended for it to be added by emberjs/ember.js#16399 (as you linked), and just no docs were added for it. However, it's also possible that it's in the bucket of "is intended to work but is not public API" and in that case we should not implement it!

@chriskrycho chriskrycho added the question Further information is requested label Mar 14, 2023
@nwhittaker
Copy link
Contributor

FWIW it is mentioned in Ember's changelog1:

emberjs/ember.js#16399 [BUGFIX] {{#each-in}} now correctly handles key="@index" (using the index/position). The new key="@key" option uses the item's key.

Footnotes

  1. https://github.com/emberjs/ember.js/blob/master/CHANGELOG.md#v320-may-31-2018

@chriskrycho
Copy link
Member

I also confirmed with @rwjblue that it's intended to work. A PR would be most welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants