Skip to content

Commit

Permalink
Refactor: use addRestOptions() for iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Sep 25, 2021
1 parent 0bd41cc commit 717066e
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions leveldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,30 +235,12 @@ function maybeError (leveldown, callback) {
return false
}

// TODO (refactor): use addRestOptions instead
function extend (xopts, opts) {
xopts.keys = opts.keys
xopts.values = opts.values
xopts.createIfMissing = opts.createIfMissing
xopts.errorIfExists = opts.errorIfExists
xopts.keyEncoding = opts.keyEncoding
xopts.valueEncoding = opts.valueEncoding
xopts.compression = opts.compression
xopts.db = opts.db
xopts.limit = opts.limit
xopts.keyAsBuffer = opts.keyAsBuffer
xopts.valueAsBuffer = opts.valueAsBuffer
xopts.reverse = opts.reverse
xopts.fillCache = opts.fillCache
return xopts
}

function fixRange (opts) {
return (!opts.reverse || (!opts.end && !opts.start)) ? opts : { start: opts.end, end: opts.start }
}

SubDown.prototype._iterator = function (opts) {
const xopts = extend(wrap(fixRange(opts), this._wrap), opts)
const xopts = addRestOptions(wrap(fixRange(opts), this._wrap), opts)
return new SubIterator(this, this.leveldown.iterator(xopts), this.prefix)
}

Expand Down

0 comments on commit 717066e

Please sign in to comment.