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

Fix key uniqueness implementation #1081

Merged
merged 1 commit into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@glimmer/reference/lib/iterable-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function uniqueKeyFor(keyFor: KeyFor) {

return (value: unknown, memo: unknown) => {
let key = keyFor(value, memo);
let count = seen.get(value) || 0;
let count = seen.get(key) || 0;

seen.set(key, count + 1);

Expand Down
16 changes: 16 additions & 0 deletions packages/@glimmer/reference/test/iterable-impl-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ module('@glimmer/reference: IterableImpl', () => {
assert.equal(keys1[0], keys2[1]);
});

test('@identity works with multiple null values', assert => {
let arr: any[] = [null];
let { target, artifacts } = initialize(arr);

let keys1 = target.toKeys();

arr.push(null);
sync(target, artifacts);

let keys2 = target.toKeys();

assert.equal(keys2.length, 2);
assert.equal(keys1[0], keys2[0]);
assert.notEqual(keys1[0], keys2[1]);
});

test('@key works', assert => {
let arr = [
{ key: 'a', name: 'Yehuda' },
Expand Down