Skip to content

Commit 26def5c

Browse files
committed
index option specifies path to sort by
1 parent 8e698a2 commit 26def5c

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

index.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ var FlumeViewLevel = require('flumeview-level')
1111
var isArray = Array.isArray
1212
var isNumber = function (n) { return 'number' === typeof n }
1313
var isObject = function (o) { return o && 'object' === typeof o && !isArray(o) }
14-
var findByKey = function (indexes, key) {
15-
for (var i = 0; i < indexes.length; i++) {
16-
if (indexes[i] && indexes[i].key === key) {
17-
return indexes[i]
18-
}
19-
}
20-
}
2114

2215
//sorted index.
2316

@@ -95,9 +88,9 @@ module.exports = function (version, opts) {
9588
q = {}
9689

9790
var index = opts.index
98-
? findByKey(indexes, opts.index)
91+
? u.findByPath(indexes, opts.index)
9992
: select(indexes, q)
100-
93+
10194
if(!index) return {scan: true}
10295
var _opts = query(index, q, exact)
10396
_opts.values = true

links.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ var Flatmap = require('pull-flatmap')
99
var FlumeViewLevel = require('flumeview-level')
1010

1111
var isArray = Array.isArray
12-
var findByKey = function (indexes, key) {
13-
for (var i = 0; i < indexes.length; i++) {
14-
if (indexes[i] && indexes[i].key === key) {
15-
return indexes[i]
16-
}
17-
}
18-
}
19-
2012
//sorted index.
2113

2214
//split this into TWO modules. flumeview-links and flumeview-query
@@ -67,8 +59,8 @@ module.exports = function (indexes, links, version) {
6759
else
6860
q = {}
6961

70-
var index = opts.index
71-
? findByKey(indexes, opts.index)
62+
var index = opts.index
63+
? u.findByPath(indexes, opts.index)
7264
: select(indexes, q)
7365

7466
if(!index)
@@ -111,4 +103,6 @@ module.exports = function (indexes, links, version) {
111103
}
112104
return index
113105
}
114-
}
106+
}
107+
108+

util.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var deepEqual = require('deep-equal')
2+
13
exports.has = function has (key, obj) {
24
if('string' === typeof key)
35
return Object.hasOwnProperty.call(obj, key)
@@ -30,4 +32,11 @@ exports.set = function set(key, value, obj) {
3032
}
3133
}
3234

35+
exports.findByPath = function (indexes, path) {
36+
return indexes.find(function (index) {
37+
return deepEqual(index.value, path)
38+
})
39+
}
40+
41+
3342

0 commit comments

Comments
 (0)