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 force-pushed the use-default-key branch from 88bb254 to 55d3622 Jun 15, 2015
@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

@mmun mmun Jun 15, 2015

Choose a reason for hiding this comment

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

Why not just typeof?

Loading

Copy link
Member

@stefanpenner stefanpenner Jun 15, 2015

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

Loading

@mmun
Copy link
Member

@mmun mmun commented Jun 15, 2015

Looks good 👍

Loading

@rwjblue rwjblue force-pushed the use-default-key branch from 55d3622 to 74211a7 Jun 15, 2015
@KTKate
Copy link

@KTKate KTKate commented Jun 15, 2015

yay 👍

Loading

@rwjblue
Copy link
Member Author

@rwjblue 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.

Loading

@mixonic
Copy link
Member

@mixonic mixonic commented Jun 15, 2015

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

Loading

@rwjblue rwjblue force-pushed the use-default-key branch 2 times, most recently from df1d4bb to d2094bb Jun 15, 2015
@rwjblue rwjblue force-pushed the use-default-key branch from d2094bb to 01a7103 Jun 16, 2015
@rwjblue
Copy link
Member Author

@rwjblue rwjblue commented Jun 16, 2015

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

Loading

rwjblue added a commit that referenced this issue 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
1 check passed
Loading
@rwjblue rwjblue deleted the use-default-key branch Jun 16, 2015
@funtusov
Copy link
Contributor

@funtusov funtusov commented Jun 17, 2015

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

Loading

@sandstrom
Copy link
Contributor

@sandstrom sandstrom commented Jun 18, 2015

Thanks!!

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants