-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
64 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,50 @@ | ||
import Ember from "ember-metal/core"; | ||
import Ember from 'ember-metal/core'; | ||
import { get } from "ember-metal/property_get"; | ||
import { guidFor } from "ember-metal/utils"; | ||
|
||
function identity(item) { | ||
let key; | ||
let type = typeof item; | ||
|
||
if (type === 'string' || type === 'number') { | ||
key = item; | ||
} else { | ||
key = guidFor(item); | ||
} | ||
|
||
return key; | ||
} | ||
export default function decodeEachKey(item, keyPath, index) { | ||
var key; | ||
var key, deprecatedSpecialKey; | ||
|
||
switch (keyPath) { | ||
case '@index': | ||
key = index; | ||
break; | ||
case '@guid': | ||
deprecatedSpecialKey = '@guid'; | ||
key = guidFor(item); | ||
break; | ||
case '@item': | ||
deprecatedSpecialKey = '@item'; | ||
key = item; | ||
break; | ||
case '@identity': | ||
key = identity(item); | ||
break; | ||
default: | ||
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; | ||
key = identity(item); | ||
} | ||
} | ||
|
||
if (typeof key === 'number') { | ||
key = String(key); | ||
} | ||
|
||
Ember.deprecate(`Using '${deprecatedSpecialKey}' with the {{each}} helper, is deprecated. Switch to '@identity' or remove 'key=' from your template.`, !deprecatedSpecialKey); | ||
|
||
return key; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters