UniqueIndex only expose the values of contained items.

This commit is contained in:
Julien Fontanet 2015-05-19 16:34:48 +02:00
parent f9c26089cd
commit bd12ade426
2 changed files with 10 additions and 34 deletions

View File

@ -71,7 +71,7 @@ export default class UniqueIndex {
const hash = computeHash(value, key) const hash = computeHash(value, key)
if (hash != null) { if (hash != null) {
itemByHash[hash] = {key, value} itemByHash[hash] = value
keysToHash[key] = hash keysToHash[key] = hash
} }
} }
@ -98,8 +98,8 @@ export default class UniqueIndex {
// Inserts item into the new hash's list if any. // Inserts item into the new hash's list if any.
if (hash != null) { if (hash != null) {
itemByHash[hash] = value
keysToHash[key] = hash keysToHash[key] = hash
itemByHash[hash] = {key, value}
} else { } else {
delete keysToHash[key] delete keysToHash[key]
} }

View File

@ -63,14 +63,8 @@ describe('UniqueIndex', function () {
it('works with existing items', function () { it('works with existing items', function () {
expect(col.indexes).to.eql({ expect(col.indexes).to.eql({
byKey: { byKey: {
[item1.key]: { [item1.key]: item1,
key: item1.id, [item2.key]: item2
value: item1
},
[item2.key]: {
key: item2.id,
value: item2
}
} }
}) })
}) })
@ -86,18 +80,9 @@ describe('UniqueIndex', function () {
return waitTicks(2).then(() => { return waitTicks(2).then(() => {
expect(col.indexes).to.eql({ expect(col.indexes).to.eql({
byKey: { byKey: {
[item1.key]: { [item1.key]: item1,
key: item1.id, [item2.key]: item2,
value: item1 [item4.key]: item4
},
[item2.key]: {
key: item2.id,
value: item2
},
[item4.key]: {
key: item4.id,
value: item4
}
} }
}) })
}) })
@ -114,14 +99,8 @@ describe('UniqueIndex', function () {
return waitTicks(2).then(() => { return waitTicks(2).then(() => {
expect(col.indexes).to.eql({ expect(col.indexes).to.eql({
byKey: { byKey: {
[item1bis.key]: { [item1bis.key]: item1bis,
key: item1.id, [item2.key]: item2
value: item1bis
},
[item2.key]: {
key: item2.id,
value: item2
}
} }
}) })
}) })
@ -133,10 +112,7 @@ describe('UniqueIndex', function () {
return waitTicks(2).then(() => { return waitTicks(2).then(() => {
expect(col.indexes).to.eql({ expect(col.indexes).to.eql({
byKey: { byKey: {
[item1.key]: { [item1.key]: item1
key: item1.id,
value: item1
}
} }
}) })
}) })