You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
727 B

var inRange = require('./range')
module.exports = function (compare) {
var hooks = []
return {
add: function (range, hook) {
var m = {range: range, hook: hook}
hooks.push(m)
//call this to remove
return function () {
var i = hooks.indexOf(m)
if(~i) return hooks.splice(i, 1)
}
},
//remove all listeners within a range.
//this will be used to close a sublevel.
removeAll: function (range) {
throw new Error('not implemented')
},
trigger: function (key, args) {
for(var i = 0; i < hooks.length; i++) {
var test = hooks[i]
if(inRange(test.range, key, compare))
test.hook.apply(this, args)
}
}
}
}