new Index() now accepts a computeHash() callback-ish.

This commit is contained in:
Julien Fontanet 2015-04-29 14:33:37 +02:00
parent cd582e2e3a
commit 0880787d68
3 changed files with 11 additions and 7 deletions

View File

@ -21,10 +21,10 @@
],
"dependencies": {
"babel-runtime": "^5",
"lodash.bind": "^3.1.0",
"lodash.callback": "^3.1.1",
"lodash.foreach": "^3.0.2",
"make-error": "^1.0.0"
"lodash.bind": "^3",
"lodash.callback": "^3",
"lodash.foreach": "^3",
"make-error": "^1"
},
"devDependencies": {
"babel": "^5",

View File

@ -1,4 +1,5 @@
import bind from 'lodash.bind'
import callback from 'lodash.callback'
import clearObject from './clear-object'
import isEmpty from './is-empty'
@ -7,7 +8,11 @@ import NotImplemented from './not-implemented'
// ===================================================================
export default class Index {
constructor () {
constructor (computeHash) {
if (computeHash) {
this.computeHash = callback(computeHash)
}
this._itemsByHash = Object.create(null)
this._keysToHash = Object.create(null)

View File

@ -57,8 +57,7 @@ describe('Index', function () {
col.add(item)
})
byGroup = new Index()
byGroup.computeHash = item => item.group
byGroup = new Index('group')
col.createIndex('byGroup', byGroup)