Skip to content

[DOC] Document the key option for {{#each-in}} - #21536

Merged
kategengler merged 1 commit into
emberjs:mainfrom
johanrd:docs-each-in-key-options
Aug 11, 2026
Merged

kategengler merged 1 commit into
emberjs:mainfrom
johanrd:docs-each-in-key-options

Conversation

@johanrd

@johanrd johanrd commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Closes #16719

{{#each-in}} accepts key=, but only {{#each}}'s special values were documented — and over entries they mean something different:

key= keys on
@key the property name, or a Map's key
omitted / @identity the entry's value, so a changed value replaces that entry's DOM
any other string a path resolved against the value

@key was called public API for {{#each-in}} in #16719 but was documented nowhere.

@index is deliberately left out: it also resolves to the property name, so it duplicates @key on a plain object and is worse on a Map keyed by objects, where every key coerces alike. Added two tests to record its behavior anyway, since #16719 calls it public API while RFC #321 (never accepted) marks it N/A.

Five tests added, each asserting DOM node identity across an update. {{#each-in}} previously had no coverage for @key, @index or path keys, and @identity appeared only incidentally in tests asserting rendered text.

Cowritten by Claude

@johanrd
johanrd force-pushed the docs-each-in-key-options branch 2 times, most recently from 8ddd607 to 6538286 Compare July 30, 2026 01:41
@johanrd
johanrd force-pushed the docs-each-in-key-options branch 3 times, most recently from 0c0fff1 to 17da333 Compare July 30, 2026 08:49
`{{#each-in}}` accepts `key=`, but only `{{#each}}`'s special values were
documented, and they mean different things when iterating entries:

- `@key` keys on the property name, or a `Map`'s key
- `@identity`, the default, keys on the entry's value, so a changed value is
  also a changed key and that entry's DOM is replaced rather than updated in
  place
- any other string is a path resolved against the value

`@index` is left undocumented: it also resolves to the property name, making it
a redundant alias for `@key` on a plain object and worse on a `Map` keyed by
objects, where every key coerces alike and entries end up reused by position.
`@key` is likewise left out of `{{#each}}`, where it returns the numeric index
and duplicates `@index`.

`@key`, `@index` and path keys had no `{{#each-in}}` coverage, and `@identity`
appeared only incidentally in tests asserting rendered text, so add tests
asserting DOM node identity across an update for each.

Refs emberjs#16719
@johanrd
johanrd force-pushed the docs-each-in-key-options branch from 17da333 to 3ab4556 Compare July 30, 2026 08:50
@kategengler
kategengler merged commit 2951859 into emberjs:main Aug 11, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation for special values of key in each template helper

2 participants