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": { "dependencies": {
"babel-runtime": "^5", "babel-runtime": "^5",
"lodash.bind": "^3.1.0", "lodash.bind": "^3",
"lodash.callback": "^3.1.1", "lodash.callback": "^3",
"lodash.foreach": "^3.0.2", "lodash.foreach": "^3",
"make-error": "^1.0.0" "make-error": "^1"
}, },
"devDependencies": { "devDependencies": {
"babel": "^5", "babel": "^5",

View File

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

View File

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