From bd12ade4264a52916e7dd2878f3a32d7ec172b01 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Tue, 19 May 2015 16:34:48 +0200 Subject: [PATCH] UniqueIndex only expose the values of contained items. --- packages/xo-collection/src/unique-index.js | 4 +- .../xo-collection/src/unique-index.spec.js | 40 ++++--------------- 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/packages/xo-collection/src/unique-index.js b/packages/xo-collection/src/unique-index.js index 36e6cb13f..321bcf4cc 100644 --- a/packages/xo-collection/src/unique-index.js +++ b/packages/xo-collection/src/unique-index.js @@ -71,7 +71,7 @@ export default class UniqueIndex { const hash = computeHash(value, key) if (hash != null) { - itemByHash[hash] = {key, value} + itemByHash[hash] = value keysToHash[key] = hash } } @@ -98,8 +98,8 @@ export default class UniqueIndex { // Inserts item into the new hash's list if any. if (hash != null) { + itemByHash[hash] = value keysToHash[key] = hash - itemByHash[hash] = {key, value} } else { delete keysToHash[key] } diff --git a/packages/xo-collection/src/unique-index.spec.js b/packages/xo-collection/src/unique-index.spec.js index cc62fa4fd..a4000ff60 100644 --- a/packages/xo-collection/src/unique-index.spec.js +++ b/packages/xo-collection/src/unique-index.spec.js @@ -63,14 +63,8 @@ describe('UniqueIndex', function () { it('works with existing items', function () { expect(col.indexes).to.eql({ byKey: { - [item1.key]: { - key: item1.id, - value: item1 - }, - [item2.key]: { - key: item2.id, - value: item2 - } + [item1.key]: item1, + [item2.key]: item2 } }) }) @@ -86,18 +80,9 @@ describe('UniqueIndex', function () { return waitTicks(2).then(() => { expect(col.indexes).to.eql({ byKey: { - [item1.key]: { - key: item1.id, - value: item1 - }, - [item2.key]: { - key: item2.id, - value: item2 - }, - [item4.key]: { - key: item4.id, - value: item4 - } + [item1.key]: item1, + [item2.key]: item2, + [item4.key]: item4 } }) }) @@ -114,14 +99,8 @@ describe('UniqueIndex', function () { return waitTicks(2).then(() => { expect(col.indexes).to.eql({ byKey: { - [item1bis.key]: { - key: item1.id, - value: item1bis - }, - [item2.key]: { - key: item2.id, - value: item2 - } + [item1bis.key]: item1bis, + [item2.key]: item2 } }) }) @@ -133,10 +112,7 @@ describe('UniqueIndex', function () { return waitTicks(2).then(() => { expect(col.indexes).to.eql({ byKey: { - [item1.key]: { - key: item1.id, - value: item1 - } + [item1.key]: item1 } }) })