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

[BUGFIX release] Default {{each}} key to @guid or @item based on type. #11461

Merged
merged 1 commit into from
Jun 16, 2015

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Jun 15, 2015

This PR uses @item as the key when the item being iterated is a string or number, and uses @guid when it is anything else.

This is an attempt at making a better default, to prevent users from having to specify a key= to each {{each}} invocation.

It is absolutely possible, that we will want to revisit this and make specifying key required in the future, but it seems that we should attempt at good defaults before making that decision.

@rwjblue rwjblue changed the title [BUGFIX release] Default {{each}} key to @guid or @index based on type. [BUGFIX release] Default {{each}} key to @guid or @item based on type. Jun 15, 2015
@@ -19,8 +19,13 @@ export default function decodeEachKey(item, keyPath, index) {
if (keyPath) {
key = get(item, keyPath);
} else {
Ember.warn('Using `{{each}}` without specifying a key can lead to unusual behavior. Please specify a `key` that identifies a unique value on each item being iterated. E.g. `{{each model key="@guid" as |item|}}`.');
key = index;
let type = typeOf(item);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just typeof?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, lets just use JS typeof here

@mmun
Copy link
Member

mmun commented Jun 15, 2015

Looks good 👍

@KTKate
Copy link

KTKate commented Jun 15, 2015

yay 👍

@rwjblue
Copy link
Member Author

rwjblue commented Jun 15, 2015

Update:

  • Use normal typeof (instead of Ember.typeOf).
  • Added @detect as a new type (makes it much easier to document the default)
  • Added API docs saying what the default is.

@mixonic
Copy link
Sponsor Member

mixonic commented Jun 15, 2015

I am +1. I've also heard many WAT about the current behavior

@rwjblue rwjblue force-pushed the use-default-key branch 2 times, most recently from df1d4bb to d2094bb Compare June 15, 2015 18:40
@rwjblue
Copy link
Member Author

rwjblue commented Jun 16, 2015

Updated (hopefully for the last time) to deprecate @guid and @item in favor of adding the default of @identity.

rwjblue added a commit that referenced this pull request Jun 16, 2015
[BUGFIX release] Default {{each}} key to @Guid or @item based on type.
@rwjblue rwjblue merged commit 6d6d9a8 into emberjs:master Jun 16, 2015
@rwjblue rwjblue deleted the use-default-key branch June 16, 2015 16:25
@funtusov
Copy link
Contributor

FYI: It seems that this commit didn't get into the 1.13.1 tag

@sandstrom
Copy link
Contributor

Thanks!! ⛵

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.

None yet

7 participants